回答編集履歴

1

補足にあわせて、サンプルコードを変更

2016/03/05 12:53

投稿

CHERRY
CHERRY

スコア25171

test CHANGED
@@ -127,3 +127,127 @@
127
127
  </html>
128
128
 
129
129
  ```
130
+
131
+ --
132
+
133
+ 追記 (2016.03.05 21:45)
134
+
135
+
136
+
137
+ 興味を持ったので、サンプルを Google Spreadsheet から、住所を取り出すようにしてみました。
138
+
139
+ KEY の部分は、Google Spreadsheet の ID です。
140
+
141
+
142
+
143
+ ```HTML
144
+
145
+ <!DOCTYPE HTML>
146
+
147
+ <html lang="ja">
148
+
149
+ <head>
150
+
151
+ <meta charset="UTF-8">
152
+
153
+ <title>Google Maps テスト</title>
154
+
155
+ <style type="text/css">
156
+
157
+ #googlemap {
158
+
159
+ width: 700px;
160
+
161
+ height: 700px;
162
+
163
+ margin: 0 auto;
164
+
165
+ }
166
+
167
+ </style>
168
+
169
+ </head>
170
+
171
+ <body>
172
+
173
+ <div id="googlemap"></div>
174
+
175
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
176
+
177
+ <script type="text/javascript">
178
+
179
+ var googleSheetUrl = "https://spreadsheets.google.com/feeds/cells/[KEY]/od6/public/basic?alt=json";
180
+
181
+ var map;
182
+
183
+ var marker = [];
184
+
185
+
186
+
187
+ function viewMap() {
188
+
189
+ var latlng = new google.maps.LatLng({lat: 35.693, lng: 139.735});
190
+
191
+ map = new google.maps.Map(document.getElementById('googlemap'), {
192
+
193
+ center: latlng,
194
+
195
+ zoom: 13
196
+
197
+ });
198
+
199
+ var geocoder = new google.maps.Geocoder();
200
+
201
+ $.get({
202
+
203
+ url: googleSheetUrl,
204
+
205
+ cache: false,
206
+
207
+ dataType: "jsonp",
208
+
209
+ success : function(data, status){
210
+
211
+ $.each(data.feed.entry, function(i, item){
212
+
213
+ geocoder.geocode(
214
+
215
+ { address: item.content.$t },
216
+
217
+ function(result, status){
218
+
219
+ if(status==google.maps.GeocoderStatus.OK){
220
+
221
+ marker[i] = new google.maps.Marker({
222
+
223
+ position: result[0].geometry.location,
224
+
225
+ map: map
226
+
227
+ });
228
+
229
+ }
230
+
231
+ }
232
+
233
+ );
234
+
235
+ });
236
+
237
+ }
238
+
239
+ });
240
+
241
+ }
242
+
243
+ </script>
244
+
245
+ <script src="https://maps.googleapis.com/maps/api/js?callback=viewMap"></script>
246
+
247
+ </body>
248
+
249
+ </html>
250
+
251
+ ```
252
+
253
+