2011-10-31 12 views
3

Googleマップをレール用に使用していますが、設定はすべて適切ですが、デフォルトのズーム番号を設定する方法はわかりません。Google Maps for Rails - センター上のマーカーは常に最大ズーム

@default_map_options = 
     id: 'map' 
     draggable: true 
     detect_location: false # should the browser attempt to use geolocation detection features of HTML5? 
     center_on_user: false # centers map on the location detected through the browser 
     center_latitude: 0 
     center_longitude: 0 
     zoom: 7 
     maxZoom: null 
     minZoom: null 
     auto_adjust : true  # adjust the map to the markers if set to true 
     auto_zoom: true   # zoom given by auto-adjust 
     bounds: []    # adjust map to these limits. Should be [{"lat": , "lng": }]  
     raw: {}     # raw json to pass additional options 

しかし、私はそれが正常に働いていたと思ういけない:私はここgmaps4rails.base.js.coffeeでそれを設定してみました。マップを作成するときにズーム番号を追加する方法はあります:私は

<%= gmaps(:markers => {:data => @json, 
         :options => {:raw => '{ animation: google.maps.Animation }' } }, 
         :map_options => { :raw => '{ disableDefaultUI: false, 
                scrollwheel: true }' }) %> 

何も何もしていないようにみえ、それはいつものおかげですべての方法をズームしています。!

+0

自動ズームを試してください:あなたのオプションで偽 –

+0

私はそれを試みました。それは何も変わらなかった。私も私のサーバーを再起動しようとしました。これらのオプションは変更していないようです –

+0

本当に理解できません:地図上にマーカーがありますか?どれも、1つ、または多く? – apneadiving

答えて

1
あなたが設定する必要が

:auto_zoom => falseを、:ズーム=>値ここで

<%= gmaps(:markers => {:data => @json, 
        :options => {:raw => '{ animation: google.maps.Animation }' } }, 
        :map_options => { :raw => '{ disableDefaultUI: false, 
               scrollwheel: true, 
               auto_zoom => false, 
               zoom => 10 }' }) %> 
2

は(私はhamlを使用することに注意しerbため<%= %>を使用してください。)働く私のソリューションです:

= gmaps("map_options" => { "detect_location" => true, "center_on_user" => true, "auto_zoom" => false, "zoom" => 16},"markers" => { "data" => @json }) 
0

あなたが達成しようとしていることを正確にはわかりませんが、私の挑戦は、自動ズームを使用すると、遠近法がすべて間違っていたことになります。私の解決策は、ベースのコーヒースクリプトの最大ズーム値を変更することでした。以下のスニペット。オートは真のままであることに注意してください。

center_longitude: 0 
    zoom: 7 
    maxZoom: 18 
    minZoom: null 
    auto_adjust : true  # adjust the map to the markers if set to true 
    auto_zoom: true   # zoom given by auto-adjust 
    bounds: []    # adjust map to these limits. Should be [{"lat": , "lng": }] 
    raw: {}     # raw json to pass additional options 

答えに記載されている他のハム解決策は、1ページでも機能します。

関連する問題