質問編集履歴
1
コードを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,4 +13,49 @@
|
|
13
13
|
(anonymous) @ js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:134
|
14
14
|
(anonymous) @ js?key=AIzaSyBzOpoIJy-9aLUOydR1E_PoMGg7itdjWpU&callback=initMap:135
|
15
15
|
|
16
|
-
すみませんが、お助けくださいませ。。
|
16
|
+
すみませんが、お助けくださいませ。。
|
17
|
+
|
18
|
+
:追記
|
19
|
+
|
20
|
+
失礼しました。コードを書いておりませんでした。
|
21
|
+
|
22
|
+
> ビュー
|
23
|
+
|
24
|
+
```Ruby
|
25
|
+
<div>
|
26
|
+
<div id="map" style='width: 100%; height: 450px;'></div>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<script type="text/javascript">
|
30
|
+
handler = Gmaps.build('Google');
|
31
|
+
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
|
32
|
+
markers = handler.addMarkers(<%=raw @hash.to_json %>);
|
33
|
+
handler.bounds.extendWith(markers);
|
34
|
+
handler.fitMapToBounds();
|
35
|
+
});
|
36
|
+
</script>
|
37
|
+
```
|
38
|
+
> コントローラー(controllers/map-controller.rb)
|
39
|
+
|
40
|
+
```Ruby
|
41
|
+
class MapController < ApplicationController
|
42
|
+
def index
|
43
|
+
@hash = Gmaps4rails.build_markers(@restaurants) do |restaurant, marker|
|
44
|
+
marker.lat restaurant.latitude
|
45
|
+
marker.lng restaurant.longitude
|
46
|
+
marker.infowindow space.mapdescription
|
47
|
+
marker.json({title: restaurant.maptitle})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
> モデル(restarurant.rb)
|
54
|
+
|
55
|
+
```Ruby
|
56
|
+
class Restaurant < ApplicationRecord
|
57
|
+
geocoded_by :mapaddress
|
58
|
+
after_validation :geocode
|
59
|
+
end
|
60
|
+
```
|
61
|
+
すみませんが、どうぞよろしくお願いいたします。
|