# Update google maps dynamically

**URL:** <https://www.ruby-forum.com/t/update-google-maps-dynamically/171014>\
**Category:** Rails\
**Created:** [June 25, 2009, 10:10am UTC](https://www.ruby-forum.com/t/update-google-maps-dynamically/171014 "2009-06-25T10:10:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![td919](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@td919](https://www.ruby-forum.com/u/td919)\
**Post date:** [June 25, 2009, 10:10am UTC](https://www.ruby-forum.com/t/update-google-maps-dynamically/171014/1 "2009-06-25T10:10:01Z")

</div>

Hi,

I am new to Ruby on Rails. I am trying to integrate Google Map with Ruby  
on Rails, and I am totally stuck. I can initiate the map centered at a  
hardcoded lat and lng in my index view, with other locations displayed  
within 25 miles.

However, I am not sure how to update the current map with results from  
search query (which would be an address or zip code) from a user. From  
server message output, search action does find markers from different  
center point, but I can’t seem to get them displayed in the current map.

The following is my search form in index view.

\<% form\_tag(search\_path, :method =\> ‘get’) do %\>  
\<%= label\_tag(:query, ‘Search for:’) %\>  
\<%= text\_field\_tag(:query) %\>  
\<%= submit\_tag(‘Search’) %\>  
\<% end %\>

The following is the route config.

map.search ‘search’, :controller =\> ‘places’, :action =\> ‘search’

The following is search.rjs (I also hardcoded @marker in search  
controller to see if the map gets updated with a new marker).

page \<\< @map.clear\_overlays  
page \<\< @map.add\_overlay(@marker)

But, all I get is the following error…

try {  
map.clearOverlays();  
map.addOverlay(addInfoWindowToMarker(new GMarker(new  
GLatLng(75.89,-42.767),{title : “Update”}),“I have been placed through  
RJS”,{}));  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
alert(‘map.clearOverlays();\nmap.addOverlay(addInfoWindowToMarker(new  
GMarker(new GLatLng(75.89,-42.767),{title : “Update”}),“I have been  
placed through RJS”,{}));’); throw e }

But, I think the real problem is not related to the javascript error. I  
am just not sure if this direction I am going is right…using search  
form, search action, and search.rjs. Updating just the map section of  
index view is missing, and I am not sure how to go about it.

If anyone could help me out, I would very much appreciate it…

Thanks,
