apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Lng Lat can't be parsed? #507

Closed varkone closed 8 years ago

varkone commented 8 years ago

Hello, I followed guide and everything works except parsing json. When I replaced static marker with this (<%=raw @hash.to_json %>) I'm getting this error in console: SyntaxError: Unexpected token '<' Due to this error I can't even see map itself Here is show.html.slim

#map style=("width: 800px; height: 400px;") 
  javascript:
    handler = Gmaps.build('Google');
    handler.buildMap({ provider: {disableDefaultUI: true}, internal: {id: 'map'}}, function(){
      markers = handler.addMarkers(<%=raw @hash.to_json %>);
      handler.bounds.extendWith(markers);
      handler.fitMapToBounds();
      handler.getMap().setZoom(5);
    });

And here is places_controller.rb/show action

def show
        @places = Places.find(params[:id])
        @hash = Gmaps4rails.build_markers(@places) do |places, marker|
           marker.lat places.latitude
           marker.lng places.longitude
        end
    end

Where's the problem?

varkone commented 8 years ago

Solved: I used this

"lat": #{@places.latitude},
"lng": #{@places.longitude}

Works fine