Ruby on RailsでGoogle Mapを表示させたいのですが、Mapの画像は表示されるものの住所位置が表示されずに困っています。
コンソールでは下記のエラーがありました。
Uncaught ReferenceError: google is not defined
at eval (eval at <anonymous> (infobox_packed.js:1), <anonymous>:1:1066)
at infobox_packed.js:1
(anonymous) @ VM469:1
(anonymous) @ infobox_packed.js:1
js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:98 Uncaught mc {message: "initMap is not a function", name: "InvalidValueError", stack: "Error↵ at new mc (https://maps.googleapis.com/m…-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:135:73"}message: "initMap is not a function"name: "InvalidValueError"stack: "Error↵ at new mc (https://maps.googleapis.com/maps/api/js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:47:499)↵ at Object._.nc (https://maps.googleapis.com/maps/api/js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:48:96)↵ at Yg (https://maps.googleapis.com/maps/api/js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:98:420)↵ at https://maps.googleapis.com/maps/api/js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:135:58↵ at Object.google.maps.Load (https://maps.googleapis.com/maps/api/js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:21:5)↵ at https://maps.googleapis.com/maps/api/js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:134:20↵ at https://maps.googleapis.com/maps/api/js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:135:73"__proto__: Error
Yg @ js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:98
(anonymous) @ js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:135
google.maps.Load @ js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:21
(anonymous) @ js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:134
(anonymous) @ js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:135
すみませんが、お助けくださいませ。。
:追記
失礼しました。コードを書いておりませんでした。
ビュー
Ruby
1 <div> 2 <div id="map" style='width: 100%; height: 450px;'></div> 3 </div> 4 5 <script type="text/javascript"> 6 handler = Gmaps.build('Google'); 7 handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 8 markers = handler.addMarkers(<%=raw @hash.to_json %>); 9 handler.bounds.extendWith(markers); 10 handler.fitMapToBounds(); 11 }); 12 </script>
コントローラー(controllers/map-controller.rb)
Ruby
1class MapController < ApplicationController 2 def index 3 @hash = Gmaps4rails.build_markers(@restaurants) do |restaurant, marker| 4 marker.lat restaurant.latitude 5 marker.lng restaurant.longitude 6 marker.infowindow space.mapdescription 7 marker.json({title: restaurant.maptitle}) 8 end 9 end 10end
モデル(restarurant.rb)
Ruby
1class Restaurant < ApplicationRecord 2 geocoded_by :mapaddress 3 after_validation :geocode 4end
すみませんが、どうぞよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/07 00:56
2017/05/07 02:54
2017/05/08 12:48