Вопрос

I have the following view in my Rails code :

<%= 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) %>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top