I'm using gmaps4rails to display a single marker, but I can't get it to not show a flash of lat/lon 0,0 water before panning over to the marker.
My (coffeescript) code is very simple:
handler = Gmaps.build('Google')
handler.buildMap { provider: {}, internal: { id: 'my-map-id' } }, ->
marker = handler.addMarker
lat: 41.0
lng: -96.0
marker.panTo()
handler.getMap().setZoom(14)
The map displays blue water then quickly jumps over to the desired location. I've tried using the bounds-oriented methods instead of the marker.panTo()
, with the same results:
handler.bounds.extendWith(marker)
handler.fitMapToBounds()
handler.getMap().setZoom(14)
It seems like I need to either prevent display of the map until the marker and location is set, or I need to add the markers in earlier. Neither of which I've figured out how to do.
Thanks to the quick tip from @apneadiving, this took care of it:
lat = 41.0
lng = -96.0
options =
center: new google.maps.LatLng(lat, lng)
zoom: 14
handler = Gmaps.build('Google')
handler.buildMap { provider: options, internal: { id: 'contact-map' } }, ->
marker = handler.addMarker
lat: lat
lng: lng