Hi,
I am trying to do a rails application that uses google map to allow users to specify longitude and latitude and then the google map should be updated to show that location which was specified.
I am using observe_field on the text field like this:
<%= observe_field 'geo_loc_cords', :url => {:action => :update_map, :form_authenticity_token => form_authenticity_token}, :update => :map, :with => '"cords="+element.value', :loading => "Element.show('spinner')", :complete => "Element.hide('spinner')" %>
and my map div looks like this:
<%= @map.div(:width => 400, :height => 300) %>
and in the update_map action I have this (hardcoded the coordinates for now):
def update_map() latitude = 43.023849 longitude = -77.682053 @map = Variable.new("map")
point = GLatLng.new([latitude, longitude]) @marker = GMarker.new(point, {:title => "Site:", :info_window => "Site:", :draggable => true}) respond_to do |format| format.html format.js end end
And my rjs template simply looks like this:
page << @map.clear_overlays page << @map.add_overlay(@marker)
Yet the result is simply outputted on the page as:
try { map.clearOverlays(); map.addOverlay(addInfoWindowToMarker(new GMarker(new GLatLng(43.023849,-77.682053),{title : "Site:",draggable : true}),"Site:",{})); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('map.clearOverlays();\nmap.addOverlay(addInfoWindowToMarker(new GMarker(new GLatLng(43.023849,-77.682053),{title : \"Site:\",draggable : true}),\"Site:\",{}));'); throw e }
What am I doing wrong to make the resulting javascript outputted on the page rather than interpreted as javascript?