質問編集履歴

1

コードを追記しました

2017/05/07 00:55

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -29,3 +29,93 @@
29
29
 
30
30
 
31
31
  すみませんが、お助けくださいませ。。
32
+
33
+
34
+
35
+ :追記
36
+
37
+
38
+
39
+ 失礼しました。コードを書いておりませんでした。
40
+
41
+
42
+
43
+ > ビュー
44
+
45
+
46
+
47
+ ```Ruby
48
+
49
+ <div>
50
+
51
+ <div id="map" style='width: 100%; height: 450px;'></div>
52
+
53
+ </div>
54
+
55
+
56
+
57
+ <script type="text/javascript">
58
+
59
+ handler = Gmaps.build('Google');
60
+
61
+ handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
62
+
63
+ markers = handler.addMarkers(<%=raw @hash.to_json %>);
64
+
65
+ handler.bounds.extendWith(markers);
66
+
67
+ handler.fitMapToBounds();
68
+
69
+ });
70
+
71
+ </script>
72
+
73
+ ```
74
+
75
+ > コントローラー(controllers/map-controller.rb)
76
+
77
+
78
+
79
+ ```Ruby
80
+
81
+ class MapController < ApplicationController
82
+
83
+ def index
84
+
85
+ @hash = Gmaps4rails.build_markers(@restaurants) do |restaurant, marker|
86
+
87
+ marker.lat restaurant.latitude
88
+
89
+ marker.lng restaurant.longitude
90
+
91
+ marker.infowindow space.mapdescription
92
+
93
+ marker.json({title: restaurant.maptitle})
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ ```
102
+
103
+
104
+
105
+ > モデル(restarurant.rb)
106
+
107
+
108
+
109
+ ```Ruby
110
+
111
+ class Restaurant < ApplicationRecord
112
+
113
+ geocoded_by :mapaddress
114
+
115
+ after_validation :geocode
116
+
117
+ end
118
+
119
+ ```
120
+
121
+ すみませんが、どうぞよろしくお願いいたします。