display google static map

how can I display a static map in my view from such a url:
http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY

how can I display a static map in my view from such a url:
http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY

http://www.google.com/search?q=google+map+static+api

First result.

http://www.google.com/search?q=google+map+static+api

First result.

I know. But how should I render that? A simple <%= image_tag(that_url)
%> is not possible...

Zoran Surname wrote:
[...]

I know. But how should I render that? A simple <%= image_tag(that_url)
%> is not possible...

So use literal HTML rather than image_tag. Remember, there's nothing
magical about helpers!

Best,

use iframe

~N A R E N

Narendra sisodiya wrote:

use iframe

Bad idea. There's no need to use an iframe to display a single image!

~N A R E N

Best,

I've already tried that but got same result...

So what was the result?

Try it again, and look at the source for your web page for that image.
That should let you see what is really and truly getting rendered by
your code. From there, you should be able to see that the API call is
correctly formed.

Ar Chron wrote:

I've already tried that but got same result...

So what was the result?

Try it again, and look at the source for your web page for that image.
That should let you see what is really and truly getting rendered by
your code. From there, you should be able to see that the API call is
correctly formed.

This is the HTML result:

<img alt="Staticmap?center=40"
src="http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY"
/>

I also tried things like:
static_map = Net::HTTP.get_response(URI.parse(map_url))
@static_map = Magick::Image::from_blob(static_map.body.read).first

<%= @static_map %> then shows me a blob:
"GIF89a� � ���...."

static_map_url =
"http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY"
static_map = open(static_map_url) { |f|
      @static_map = Magick::Image::from_blob(f.read).first
    }

In the console I get then
=> GIF 512x512 512x512+0+0 PseudoClass 256c 8-bit 77kb
@static_map.rows
=> 512

The image is there but I don't know how to render this one.

Forgot to mention: it's a parial which is called by

<% content_for(:x) do %>
  <%= render :partial => 'y' %>
<% end %>

Ar Chron wrote:

I've already tried that but got same result...

So what was the result?

Try it again, and look at the source for your web page for that image.
That should let you see what is really and truly getting rendered by
your code. From there, you should be able to see that the API call is
correctly formed.

This is the HTML result:

<img alt="Staticmap?center=40"
src="http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY"
/>

That link does not work, past it into browser and see. I guess it is
due to the &amp; in there.

I also tried things like:
static_map = Net::HTTP.get_response(URI.parse(map_url))
@static_map = Magick::Image::from_blob(static_map.body.read).first

<%= @static_map %> then shows me a blob:
"GIF89a� � ���...."

static_map_url =
"http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY"

That link does work.

Colin

The link (with &amp; in img tag) works, but as I mentioned before only
if the img tag is not in a partial called by

<% content_for(:x) do %>
<%= render :partial => 'y' %>
<% end %>
--

Well I just pasted
http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY
into FF and it didn't work. (404 not found)

Colin

Colin Law wrote:

True, I should have paid more attention to what you wrote. So if I
understand correctly you are saying the the html

<img alt="Staticmap?center=40"
src="http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mobile&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&key=MAPS_API_KEY"
/>

works sometimes but not if generated by a partial? If so then I would
suggest it is something to do with the html around the img tag rather
than the tag itself. Have you tried pasting the complete page source
into the html validator at http://validator.w3.org/#validate_by_input

Colin

I believe that the browser cannot tell how the the html was generated,
it just interprets the html. Can you remove as much as possible from
the page that does not work and post the complete (html) source?

Colin