質問編集履歴
5
code
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
```
|
22
|
+
|
21
23
|
function initMap()
|
22
24
|
|
23
25
|
{
|
@@ -52,10 +54,14 @@
|
|
52
54
|
|
53
55
|
}
|
54
56
|
|
57
|
+
```
|
58
|
+
|
55
59
|
|
56
60
|
|
57
61
|
太文字になっている場所のlatとlngを取得し、以下のlatitudeとlongitudeに数値を代入しようと考えてきます。
|
58
62
|
|
63
|
+
```
|
64
|
+
|
59
65
|
var params = {
|
60
66
|
|
61
67
|
keyid: '',
|
@@ -72,6 +78,8 @@
|
|
72
78
|
|
73
79
|
};
|
74
80
|
|
81
|
+
```
|
82
|
+
|
75
83
|
|
76
84
|
|
77
85
|
代入は
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -260,20 +260,6 @@
|
|
260
260
|
|
261
261
|
<br>
|
262
262
|
|
263
|
-
<!-- <form name="station">
|
264
|
-
|
265
|
-
<select name="station_name" id="station_name">
|
266
|
-
|
267
|
-
<option value="*" selected>駅名を選択してください</option>
|
268
|
-
|
269
|
-
<option value="34.971470&138.389172">静岡駅</option>
|
270
|
-
|
271
|
-
<option value="34.703450&137.734828">浜松駅</option>
|
272
|
-
|
273
|
-
</select>
|
274
|
-
|
275
|
-
</form> -->
|
276
|
-
|
277
263
|
<br>
|
278
264
|
|
279
265
|
<br>
|
3
キー削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -164,7 +164,7 @@
|
|
164
164
|
|
165
165
|
<div id="map"></div>
|
166
166
|
|
167
|
-
<script src="https://maps.googleapis.com/maps/api/js?key=AI
|
167
|
+
<script src="https://maps.googleapis.com/maps/api/js?key={APIkey}></script>
|
168
168
|
|
169
169
|
<script>
|
170
170
|
|
2
ソースコード全体を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -81,3 +81,403 @@
|
|
81
81
|
params.longitude = myLatLng.lng();
|
82
82
|
|
83
83
|
上記のコードで代入しようと考えたのですがうまく動きませんでした。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
<!DOCTYPE html>
|
90
|
+
|
91
|
+
<html lang="ja" dir="ltr">
|
92
|
+
|
93
|
+
<head>
|
94
|
+
|
95
|
+
<title>J14014 課題1</title>
|
96
|
+
|
97
|
+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
|
98
|
+
|
99
|
+
<meta charset="utf-8">
|
100
|
+
|
101
|
+
<style>
|
102
|
+
|
103
|
+
html, body {
|
104
|
+
|
105
|
+
height: 100%;
|
106
|
+
|
107
|
+
margin: 0;
|
108
|
+
|
109
|
+
padding: 0;
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
#map {
|
114
|
+
|
115
|
+
height: 500px;
|
116
|
+
|
117
|
+
width: 50%;
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
#floating-panel {
|
122
|
+
|
123
|
+
position: absolute;
|
124
|
+
|
125
|
+
top: 10px;
|
126
|
+
|
127
|
+
left: 35%;
|
128
|
+
|
129
|
+
z-index: 5;
|
130
|
+
|
131
|
+
background-color: #fff;
|
132
|
+
|
133
|
+
padding: 5px;
|
134
|
+
|
135
|
+
border: 1px solid #999;
|
136
|
+
|
137
|
+
text-align: center;
|
138
|
+
|
139
|
+
font-family: 'Roboto','sans-serif';
|
140
|
+
|
141
|
+
line-height: 30px;
|
142
|
+
|
143
|
+
padding-left: 10px;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
</style>
|
150
|
+
|
151
|
+
</head>
|
152
|
+
|
153
|
+
<body>
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
<div id="floating-panel">
|
158
|
+
|
159
|
+
<input id="address" type="textbox" value="">
|
160
|
+
|
161
|
+
<input id="submit" type="button" value="Geocode">
|
162
|
+
|
163
|
+
</div>
|
164
|
+
|
165
|
+
<div id="map"></div>
|
166
|
+
|
167
|
+
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyChLNW7VHQYfpisx2CK4gGabx5qjqElp-g"></script>
|
168
|
+
|
169
|
+
<script>
|
170
|
+
|
171
|
+
function initMap()
|
172
|
+
|
173
|
+
{
|
174
|
+
|
175
|
+
var myLatLng = {lat: 35.658581, lng: 139.745433};
|
176
|
+
|
177
|
+
var map = new google.maps.Map(document.getElementById('map'), {
|
178
|
+
|
179
|
+
zoom: 15,
|
180
|
+
|
181
|
+
center: myLatLng
|
182
|
+
|
183
|
+
});
|
184
|
+
|
185
|
+
var marker = new google.maps.Marker({
|
186
|
+
|
187
|
+
position: myLatLng,
|
188
|
+
|
189
|
+
map: map
|
190
|
+
|
191
|
+
});
|
192
|
+
|
193
|
+
var geocoder = new google.maps.Geocoder();
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
document.getElementById('submit').addEventListener('click', function() {
|
198
|
+
|
199
|
+
geocodeAddress(geocoder, map);
|
200
|
+
|
201
|
+
});
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
function geocodeAddress(geocoder, resultsMap)
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
var address = document.getElementById('address').value;
|
212
|
+
|
213
|
+
geocoder.geocode({'address': address}, function(results, status) {
|
214
|
+
|
215
|
+
if (status === google.maps.GeocoderStatus.OK) {
|
216
|
+
|
217
|
+
resultsMap.setCenter(results[0].geometry.location);
|
218
|
+
|
219
|
+
var marker = new google.maps.Marker({
|
220
|
+
|
221
|
+
map: resultsMap,
|
222
|
+
|
223
|
+
position: results[0].geometry.location
|
224
|
+
|
225
|
+
});
|
226
|
+
|
227
|
+
} else {
|
228
|
+
|
229
|
+
alert('Geocode was not successful for the following reason: ' + status);
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
});
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
initMap();
|
238
|
+
|
239
|
+
</script>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
<a href="http://www.gnavi.co.jp/">
|
244
|
+
|
245
|
+
<img src="http://apicache.gnavi.co.jp/image/rest/b/api_265_65.gif" width="265" height="65" border="0" alt="グルメ情報検索サイト ぐるなび">
|
246
|
+
|
247
|
+
</a>
|
248
|
+
|
249
|
+
<input type="hidden" value="2aac5d7fc6cc734c236af8f5511b353f" class="js--key">
|
250
|
+
|
251
|
+
<br>
|
252
|
+
|
253
|
+
<br>
|
254
|
+
|
255
|
+
<label for="freeword">フリーワード検索</label>
|
256
|
+
|
257
|
+
<input type="text" name="freeword" id="freeword" value="" class="js--freeword" />
|
258
|
+
|
259
|
+
<br>
|
260
|
+
|
261
|
+
<br>
|
262
|
+
|
263
|
+
<!-- <form name="station">
|
264
|
+
|
265
|
+
<select name="station_name" id="station_name">
|
266
|
+
|
267
|
+
<option value="*" selected>駅名を選択してください</option>
|
268
|
+
|
269
|
+
<option value="34.971470&138.389172">静岡駅</option>
|
270
|
+
|
271
|
+
<option value="34.703450&137.734828">浜松駅</option>
|
272
|
+
|
273
|
+
</select>
|
274
|
+
|
275
|
+
</form> -->
|
276
|
+
|
277
|
+
<br>
|
278
|
+
|
279
|
+
<br>
|
280
|
+
|
281
|
+
<input type="button" value="店舗結果" class="js--apply" />
|
282
|
+
|
283
|
+
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
|
284
|
+
|
285
|
+
<script>
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
(function(){
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
var url = 'http://api.gnavi.co.jp/RestSearchAPI/20150630/?callback=?';
|
294
|
+
|
295
|
+
var params = {
|
296
|
+
|
297
|
+
keyid: '',
|
298
|
+
|
299
|
+
format: 'json',
|
300
|
+
|
301
|
+
latitude: 0,
|
302
|
+
|
303
|
+
longitude: 0,
|
304
|
+
|
305
|
+
range: 2,
|
306
|
+
|
307
|
+
freeword: ''
|
308
|
+
|
309
|
+
};
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
var showResult = function(result){
|
314
|
+
|
315
|
+
if ( result.total_hit_count > 0 ) {
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
document.write(result.total_hit_count + '件の結果が見つかりました。');
|
320
|
+
|
321
|
+
document.write('<br>');
|
322
|
+
|
323
|
+
document.write('現在の仕様では最大10件しか表示できません。\n');
|
324
|
+
|
325
|
+
document.write('<table border=1 id="id33a">');
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
document.write('<tr>');
|
330
|
+
|
331
|
+
document.write('<td>店舗ID</td>');
|
332
|
+
|
333
|
+
document.write('<td>店舗名</td>');
|
334
|
+
|
335
|
+
document.write('<td>路線名</td>');
|
336
|
+
|
337
|
+
document.write('<td>駅名</td>');
|
338
|
+
|
339
|
+
document.write('<td>徒歩(分)</td>');
|
340
|
+
|
341
|
+
document.write('</tr>');
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
for ( var i in result.rest ){
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
document.write('<tr>');
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
<!-- 店舗ID -->
|
354
|
+
|
355
|
+
if ( result.rest[i].id == '[object Object]'){
|
356
|
+
|
357
|
+
document.write('<td></td>');
|
358
|
+
|
359
|
+
}else{
|
360
|
+
|
361
|
+
document.write('<td>'+ result.rest[i].id + '</td>');
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
<!-- 店舗名 -->
|
368
|
+
|
369
|
+
if ( result.rest[i].name == '[object Object]'){
|
370
|
+
|
371
|
+
document.write('<td></td>');
|
372
|
+
|
373
|
+
}else{
|
374
|
+
|
375
|
+
document.write('<td>'+ result.rest[i].name + '</td>');
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
<!-- 路線名 -->
|
382
|
+
|
383
|
+
if ( result.rest[i].access.line == '[object Object]'){
|
384
|
+
|
385
|
+
document.write('<td></td>');
|
386
|
+
|
387
|
+
}else{
|
388
|
+
|
389
|
+
document.write('<td>'+ result.rest[i].access.line + '</td>');
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
<!-- 駅名 -->
|
396
|
+
|
397
|
+
if ( result.rest[i].access.station == '[object Object]'){
|
398
|
+
|
399
|
+
document.write('<td></td>');
|
400
|
+
|
401
|
+
}else{
|
402
|
+
|
403
|
+
document.write('<td>'+ result.rest[i].access.station + '</td>');
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
<!-- 徒歩(分)-->
|
410
|
+
|
411
|
+
if ( result.rest[i].access.walk == '[object Object]'){
|
412
|
+
|
413
|
+
document.write('<td></td>');
|
414
|
+
|
415
|
+
}else{
|
416
|
+
|
417
|
+
document.write('<td>'+ result.rest[i].access.walk + '分'+ '</td>');
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
document.write('</tr>');
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
document.write('</table>');
|
432
|
+
|
433
|
+
document.write('<a href="ぐるなびAPI.html">戻る</a>');
|
434
|
+
|
435
|
+
} else {
|
436
|
+
|
437
|
+
alert( '検索結果が見つかりませんでした。' );
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
$(document).on('click', '.js--apply', function(){
|
446
|
+
|
447
|
+
params.keyid = $('.js--key').val();
|
448
|
+
|
449
|
+
//params.latitude = station_name.value.split("&")[0];
|
450
|
+
|
451
|
+
//params.longitude = station_name.value.split("&")[1];
|
452
|
+
|
453
|
+
params.latitude = myLatLng.lat();
|
454
|
+
|
455
|
+
params.longitude = myLatLng.lng();
|
456
|
+
|
457
|
+
params.freeword = $('.js--freeword').val();
|
458
|
+
|
459
|
+
$.getJSON(url, params, function(result){
|
460
|
+
|
461
|
+
showResult(result);
|
462
|
+
|
463
|
+
});
|
464
|
+
|
465
|
+
});
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
})(jQuery);
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
</script>
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
</body>
|
478
|
+
|
479
|
+
</html>
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
```
|
1
ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,69 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
GoogleMapAPIを使わなくてもいいのですがサンプルコードのようなものを教えてくださると助かります。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
function initMap()
|
22
|
+
|
23
|
+
{
|
24
|
+
|
25
|
+
**var myLatLng = {lat: 35.658581, lng: 139.745433};**
|
26
|
+
|
27
|
+
var map = new google.maps.Map(document.getElementById('map'), {
|
28
|
+
|
29
|
+
zoom: 15,
|
30
|
+
|
31
|
+
center: **myLatLng**
|
32
|
+
|
33
|
+
});
|
34
|
+
|
35
|
+
var marker = new google.maps.Marker({
|
36
|
+
|
37
|
+
position: myLatLng,
|
38
|
+
|
39
|
+
map: map
|
40
|
+
|
41
|
+
});
|
42
|
+
|
43
|
+
var geocoder = new google.maps.Geocoder();
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
document.getElementById('submit').addEventListener('click', function() {
|
48
|
+
|
49
|
+
geocodeAddress(geocoder, map);
|
50
|
+
|
51
|
+
});
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
太文字になっている場所のlatとlngを取得し、以下のlatitudeとlongitudeに数値を代入しようと考えてきます。
|
58
|
+
|
59
|
+
var params = {
|
60
|
+
|
61
|
+
keyid: '',
|
62
|
+
|
63
|
+
format: 'json',
|
64
|
+
|
65
|
+
latitude: 0,
|
66
|
+
|
67
|
+
longitude: 0,
|
68
|
+
|
69
|
+
range: 2,
|
70
|
+
|
71
|
+
freeword: ''
|
72
|
+
|
73
|
+
};
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
代入は
|
78
|
+
|
79
|
+
params.latitude = myLatLng.lat();
|
80
|
+
|
81
|
+
params.longitude = myLatLng.lng();
|
82
|
+
|
83
|
+
上記のコードで代入しようと考えたのですがうまく動きませんでした。
|