\'json\', \'auto_adjust\' => false, \'auto_zoom\' => false, \'zoom\' => 10 }) %>" />
开发者

Gmaps4rails : zoom not working?

开发者 https://www.devze.com 2023-03-02 15:38 出处:网络
I have the following view in my Rails code : 开发者_如何学Python <%= gmaps4rails(@map,{ \"processing\" => \'json\', \'auto_adjust\' => false, \'auto_zoom\' => false, \'zoom\' => 10 }) %>

I have the following view in my Rails code :

开发者_如何学Python

<%= gmaps4rails(@map, { "processing" => 'json', 'auto_adjust' => false, 'auto_zoom' => false, 'zoom' => 10 }) %>

I have only one marker on my map. When I display the map, the zoom is always set to the maximum, despite the options I set above. Did I forget an option ?


Try this instead (the gmaps method lets you pass in options, whereas the gmaps4rails method does not):

<%= gmaps("markers" => {"data" => @map}, "map_options" => {"processing" => "json", "auto_adjust" => false, "auto_zoom" => false, "zoom" => 10}) %>

See http://rubydoc.info/gems/gmaps4rails/0.8.1/ApplicationHelper for documentation on these two methods (gmaps vs gmaps4rails)


I was able to get zoom working by setting a center position

I did this in the controller:

@gmaps_options = {
  "map_options" => {
    "auto_zoom" => false,
    "zoom" => 12,
    "center_latitude" => @event.lat,
    "center_longitude" => @event.long
  },
  "markers" => {
    "data" => @event.to_gmaps4rails
  }
}

And then this in the view

<%= gmaps(@gmap_options) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消