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.

google map static api - Google Search

First result.

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

Zoran S. 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,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

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,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

use iframe

~N A R E N

On Tue, Jun 16, 2009 at 2:46 PM, Marnen Laibow-Koser <

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.

Marnen Laibow-Koser wrote:

Zoran S. 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,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I’ve already tried that but got same result…

Well, the img tag works! But only if it’s not in a partial. Why is that?

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:

Staticmap?center=40

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 %>

2009/6/17 Zoran S. [email protected]:

This is the HTML result:

Staticmap?center=40

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

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 & 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 %>

2009/6/17 Zoran S. [email protected]:

The link (with & 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&amp;zoom=14&amp;size=512x512&amp;maptype=mobile&amp;markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&amp;key=MAPS_API_KEY
into FF and it didn’t work. (404 not found)

Colin

Colin L. wrote:

2009/6/17 Zoran S. [email protected]:

The link (with & 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&amp;zoom=14&amp;size=512x512&amp;maptype=mobile&amp;markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc&amp;key=MAPS_API_KEY
into FF and it didn’t work. (404 not found)

Colin

Yes, in a browser. But try that in img tag and you will see it works.

I tried that in a new empty document. Not the partial by itself causes
is the problem but the <% content_for(:x) do %> containing the partial.
The result is a valid html image tag and the src url is correct but the
image is curiously not displayed.

2009/6/17 Zoran S. [email protected]:

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

Colin

Yes, in a browser. But try that in img tag and you will see it works.

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

Staticmap?center=40

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 The W3C Markup Validation Service

Colin

2009/6/17 Zoran S. [email protected]:

I tried that in a new empty document. Not the partial by itself causes
is the problem but the <% content_for(:x) do %> containing the partial.
The result is a valid html image tag and the src url is correct but the
image is curiously not displayed.

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