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.