参考サイトを元に実装したのですがmapの中身が表示されません、値はしっかり入っています。
どうしたらしっかり表示できるでしょうか?
map/index.html.erb
ruby
1 2<div style='width: 800px;'> 3 <div id="map" style='width: 800px; height: 400px;'></div> 4</div> 5 6<script type="text/javascript"> 7 handler = Gmaps.build('Google'); 8 handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 9 markers = handler.addMarkers(<%=raw @hash.to_json %>); 10 handler.bounds.extendWith(markers); 11 handler.fitMapToBounds(); 12 }); 13</script>
MapController
ruby
1 def index 2 @items = Item.all 3 @hash = Gmaps4rails.build_markers(@items) do |item, marker| 4 marker.lat item.latitude 5 marker.lng item.longitude 6 marker.json({title: item.title}) 7 end 8 end
因みにmap/index.html.erbを下記のように書き直すと正しく表示されます。
ruby
1 2 3<div style='width: 100%; '> 4 <div id="map" style='width: 100%; height: 400px;'></div> 5</div> 6 7<script type="text/javascript"> 8 handler = Gmaps.build('Google'); 9 handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 10 markers = handler.addMarkers([ 11 { 12 "lat": 0, 13 "lng": 0, 14 "picture": { 15 "url": "http://people.mozilla.com/~faaborg/files/shiretoko/firefoxIcon/firefox-32.png", 16 "width": 32, 17 "height": 32 18 }, 19 "infowindow": "hello!" 20 } 21 ]); 22 handler.bounds.extendWith(markers); 23 handler.fitMapToBounds(); 24 }); 25</script> 26
マップ表示につかってるソースを記載ください。
ミニマム化しても結構です。
多分 long / lat の値がOutofRange していると思いますが
追加いたしました。新規でアプリを作る場合は表示されるのですが、既存のアプリに実装したら映らなくなりました。既存のアプリはTurbolinksをoffにしています。
https://teratail.com/questions/42805 これと同じ内容では?
内容は同じですが、参考サイトと実装コードが違います。
あなたの回答
tips
プレビュー