0

I am using gmaps4rails and geocoder gem to display all the matching current location from database. This is the code from the controller.

def map_view
    @users = User.where(city: params[:city])
    @hash = Gmaps4rails.build_markers(@users) do |user, marker|
      marker.lat user.latitude
      marker.lng user.longitude
    end
    respond_to do |format|
      format.html
      format.js
    end
    puts 'coordinates', @hash
end

When I try to use the @hash object in the view, the object is null.

<script type="text/javascript">
    handler = Gmaps.build('Google');
    handler.buildMap({ provider: {}, internal: {id: 'map_location'}}, function(){
    markers = handler.addMarkers(<%=raw @hash.to_json %>);
    handler.bounds.extendWith(markers);
    handler.fitMapToBounds();
  });
</script>

The above is the code in the view. The map displays with empty object. The browser console shows this error Uncaught RangeError: Maximum call stack size exceeded.

When I print from the controller the object is not null. Here is the output from the server.

I am new. I appreciate your help.

abielita
  • 13,147
  • 2
  • 17
  • 59
mbd
  • 19
  • 5

1 Answers1

0

Make sure that you're not passing in nil values for marker.lat and marker.lng. Based also from this forum, "In your json, you should replace: longitude with lng and latitude with lat." Check this related issue on GitHub.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • The passed values are not `nil`. I guess the issue is after the value is being passed in `lat` and `long`. – mbd May 17 '16 at 16:43