apneadiving / Google-Maps-for-Rails

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

trying to center google map to particular coordinates #340

Closed tansaku closed 11 years ago

tansaku commented 11 years ago

Hi there, love gmap4rails. Having trouble with centering the map:

<%= gmaps("map_options" => { "auto_adjust" => false, "auto_zoom" => false, "center" => "new google.maps.LatLng(51.54752933190869, -0.3764533996582031)", "zoom" => 12},"markers" => { "data" => @json }) %>

produces

Gmaps.map = new Gmaps4RailsGoogle(); Gmaps.load_map = function() { Gmaps.map.map_options.auto_adjust = false; Gmaps.map.map_options.auto_zoom = false; Gmaps.map.map_options.center = "new google.maps.LatLng(51.54752933190869, -0.3764533996582031)"; Gmaps.map.map_options.zoom = 12; Gmaps.map.initialize(); Gmaps.map.markers = [{"description":"Harrow Baptist Church","lat":51.5795877,"lng":-0.3350667}]; Gmaps.map.create_markers(); Gmaps.map.adjustMapToBounds(); Gmaps.map.callback(); }; Gmaps.oldOnload = window.onload; window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };

which fails because the javascript is wrapped in quotes. we've tried center_longitude and center_latitude to no joy.

Any suggestions very gratefully received

tansaku commented 11 years ago

I also note that center_longitude and friend don't appear in the gmaps v3 spec: https://developers.google.com/maps/documentation/javascript/reference#MapOptions

apneadiving commented 11 years ago

Look here how I proceed: https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/spec/dummy/app/views/users/index.html.erb#L62

tansaku commented 11 years ago

thanks! Actually I just got it working with:

<%= gmaps("map_options" => { "auto_adjust" => false, "auto_zoom" => true, "center_latitude" => 51.54752933190869, "center_longitude" => -0.3764533996582031, "zoom" => 12},"markers" => { "data" => @json }) %>

following the advice to set auto_zoom to true in this post:

http://stackoverflow.com/questions/12332891/how-to-center-map-in-gmaps4rails

weird, because previously I needed to set that to false to get the zoom level working ...

Many thanks either way :-)