Topic: YM4R/GM and AJAX

hi,

I want to use YM4R/GM (which is the Google Maps plugin for rails) to render a map based on an AJAX form. I'd like the form to appear initially and after it's submitted for the map to appear below it.

The problem is that script tags and some javascript need to be inserted in the <head> tag when the page is rendered. Now if I render the form and the Google Maps javascript before the form is submitted the map appears with the form, which is not the behavior I'm looking for. Three possible solutions I thought of would be to

1. modify the <head> tag contents when the form is submitted or
2. somehow to hide the <div> holding the map until the form is submitted or
3. to cause YM4R/GM to play nice with AJAX (but I have no idea if that's possible).

I can do 2 easily with a listener but that seems like a very ugly solution. Any ideas on how to do 1 or preferably 3?

thanks,
Jon.

Re: YM4R/GM and AJAX

Hi,

were you able to display the map in ajax way? I mean, were u able to use link_to_remote link , say, 'show map' and then updating a div in the page to display the map. I am not able to do this. I can display the map using link_to. But when I am using link_to_remote, map is not getting displayed. I am not getting any errors. Any help on this?

Thanks,
Anu


dannoura wrote:

hi,

I want to use YM4R/GM (which is the Google Maps plugin for rails) to render a map based on an AJAX form. I'd like the form to appear initially and after it's submitted for the map to appear below it.

The problem is that script tags and some javascript need to be inserted in the <head> tag when the page is rendered. Now if I render the form and the Google Maps javascript before the form is submitted the map appears with the form, which is not the behavior I'm looking for. Three possible solutions I thought of would be to

1. modify the <head> tag contents when the form is submitted or
2. somehow to hide the <div> holding the map until the form is submitted or
3. to cause YM4R/GM to play nice with AJAX (but I have no idea if that's possible).

I can do 2 easily with a listener but that seems like a very ugly solution. Any ideas on how to do 1 or preferably 3?

thanks,
Jon.

Re: YM4R/GM and AJAX

I can't even remember what I did with this in the end, it was a long time ago. I'm guessing your best bet would be to load the map normally when the page loads in a div with style="visibility:hidden" and then show it after the AJAX call. This has the added benefit of being much faster since you don't have to reload the whole JS for Google maps. In general, however, if I had to do this today I'd skip YM4R/GM entirely and just go with the JS SDK.

Last edited by dannoura (2011-10-25 07:37:10)