質問編集履歴

3

2016/10/12 14:50

投稿

aba623ky
aba623ky

スコア63

test CHANGED
File without changes
test CHANGED
@@ -92,9 +92,9 @@
92
92
 
93
93
  <?php
94
94
 
95
- echo $r->lng;
95
+ echo $rest->lng;
96
-
96
+
97
- echo $r->lat;
97
+ echo $rest->lat;
98
98
 
99
99
  ?>
100
100
 

2

緯度経度が間違っていたので訂正します。また、補足があります。

2016/10/12 14:50

投稿

aba623ky
aba623ky

スコア63

test CHANGED
File without changes
test CHANGED
@@ -2,8 +2,20 @@
2
2
 
3
3
 
4
4
 
5
+ 写真のようになりました。
6
+
7
+
8
+
9
+ ![イメージ説明](864d9dcfbb3f0e34e7804a07780b2df1.png)
10
+
11
+
12
+
5
13
  このように書きました。
6
14
 
15
+
16
+
17
+
18
+
7
19
  ```
8
20
 
9
21
  <?php
@@ -74,6 +86,22 @@
74
86
 
75
87
  ?>
76
88
 
89
+
90
+
91
+ ///下記のphpタグのコードは各店舗の緯度経度がちゃんと入っているか確認するものです。実際入っていました。
92
+
93
+ <?php
94
+
95
+ echo $r->lng;
96
+
97
+ echo $r->lat;
98
+
99
+ ?>
100
+
101
+
102
+
103
+
104
+
77
105
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
78
106
 
79
107
  <html>
@@ -92,6 +120,178 @@
92
120
 
93
121
  {
94
122
 
123
+ var lat =35.60472;
124
+
125
+ var lng =140.12333 ;
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ var latlng = new google.maps.LatLng(lat, lng);
134
+
135
+ var mapOptions = {
136
+
137
+ zoom: 12,
138
+
139
+ center: latlng,
140
+
141
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
142
+
143
+ scaleControl: true
144
+
145
+ };
146
+
147
+ var mapObj = new google.maps.Map(document.getElementById('gmap'), mapOptions);
148
+
149
+
150
+
151
+ var marker = new google.maps.Marker({
152
+
153
+ position: {lat:$rest->$lat, lng:$rest->$lng },
154
+
155
+ map: mapObj
156
+
157
+ });
158
+
159
+ });
160
+
161
+ </script>
162
+
163
+ </head>
164
+
165
+ <body>
166
+
167
+ <div id="gmap" style="width: 500px; height: 370px; border: 1px solid Gray;">
168
+
169
+ </div>
170
+
171
+ </body>
172
+
173
+ </html>
174
+
175
+ <?php
176
+
177
+ }
178
+
179
+ }
180
+
181
+ ?>
182
+
183
+ ```
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+ ホットペーパーapiのレスポンスフィールドの$latと$lng (緯度経度)をgoogle map apiにその値を渡し、地図に位置情報を表したいです。
196
+
197
+
198
+
199
+ ```php
200
+
201
+ $rest->$lat;
202
+
203
+ $rest->$lng;
204
+
205
+ ```
206
+
207
+
208
+
209
+ としました。
210
+
211
+ http://qiita.com/ShibuyaKosuke/items/452928e235d4b1d10475
212
+
213
+ 参照しているサイトによると,
214
+
215
+
216
+
217
+ ```php
218
+
219
+ var bounds = new google.maps.LatLngBounds();
220
+
221
+
222
+
223
+ for (var i = 0; i < shops.length; i++) {
224
+
225
+ var marker = new google.maps.Marker({
226
+
227
+ position: {
228
+
229
+ lat: parseFloat(shops[i].getAttribute('data-lat'))
230
+
231
+ , lng: parseFloat(shops[i].getAttribute('data-lng'))
232
+
233
+ },
234
+
235
+ map: map
236
+
237
+ });
238
+
239
+ bounds.extend(marker.position);
240
+
241
+ }
242
+
243
+ map.fitBounds(bounds);
244
+
245
+ ```
246
+
247
+
248
+
249
+ この部分がヒントになりそうです。
250
+
251
+ このコードを見ると、店舗のlat, lngをpositionに入れて、markerを作成しているため僕も見よう見まねで
252
+
253
+ ```php
254
+
255
+ var marker = new google.maps.Marker({
256
+
257
+ position: {lat: <?= $lat ?>, lng: <?= $lng ?>},
258
+
259
+ map: mapObj
260
+
261
+ });
262
+
263
+ ```
264
+
265
+ と作成しましたが、マップ自体が表示されません。
266
+
267
+ どうやればレスポンスフィールドで得た緯度経度をgooglemapapiのpositionに渡しmarkerを作成して地図を表示できるのかわかりません。
268
+
269
+
270
+
271
+ ご教授お願いします。
272
+
273
+
274
+
275
+ ```
276
+
277
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
278
+
279
+ <html>
280
+
281
+ <head>
282
+
283
+ <title>Google Maps V3</title>
284
+
285
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
286
+
287
+ <script type="text/javascript" src="http://maps.google.com/maps/api/js?&sensor=false"></script>
288
+
289
+ <script type="text/javascript">
290
+
291
+ google.maps.event.addDomListener(window, 'load', function()
292
+
293
+ {
294
+
95
295
  var lat =35.68944;
96
296
 
97
297
  var lng =139.69167 ;
@@ -118,7 +318,7 @@
118
318
 
119
319
  var marker = new google.maps.Marker({
120
320
 
121
- position: {lat:$rest->$lat, lng:$rest->$lng },
321
+ position: {lat: <?= $r->$lat ?>, lng: <?= $r->$lng ?>},
122
322
 
123
323
  map: mapObj
124
324
 
@@ -128,172 +328,4 @@
128
328
 
129
329
  </script>
130
330
 
131
- </head>
132
-
133
- <body>
134
-
135
- <div id="gmap" style="width: 500px; height: 370px; border: 1px solid Gray;">
136
-
137
- </div>
138
-
139
- </body>
140
-
141
- </html>
142
-
143
- <?php
144
-
145
- }
146
-
147
- }
148
-
149
- ?>
150
-
151
- ```
331
+ ```
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
- ホットペーパーapiのレスポンスフィールドの$latと$lng (緯度経度)をgoogle map apiにその値を渡し、地図に位置情報を表したいです。
164
-
165
-
166
-
167
- ```php
168
-
169
- $rest->$lat;
170
-
171
- $rest->$lng;
172
-
173
- ```
174
-
175
-
176
-
177
- としました。
178
-
179
- http://qiita.com/ShibuyaKosuke/items/452928e235d4b1d10475
180
-
181
- 参照しているサイトによると,
182
-
183
-
184
-
185
- ```php
186
-
187
- var bounds = new google.maps.LatLngBounds();
188
-
189
-
190
-
191
- for (var i = 0; i < shops.length; i++) {
192
-
193
- var marker = new google.maps.Marker({
194
-
195
- position: {
196
-
197
- lat: parseFloat(shops[i].getAttribute('data-lat'))
198
-
199
- , lng: parseFloat(shops[i].getAttribute('data-lng'))
200
-
201
- },
202
-
203
- map: map
204
-
205
- });
206
-
207
- bounds.extend(marker.position);
208
-
209
- }
210
-
211
- map.fitBounds(bounds);
212
-
213
- ```
214
-
215
-
216
-
217
- この部分がヒントになりそうです。
218
-
219
- このコードを見ると、店舗のlat, lngをpositionに入れて、markerを作成しているため僕も見よう見まねで
220
-
221
- ```php
222
-
223
- var marker = new google.maps.Marker({
224
-
225
- position: {lat: <?= $lat ?>, lng: <?= $lng ?>},
226
-
227
- map: mapObj
228
-
229
- });
230
-
231
- ```
232
-
233
- と作成しましたが、マップ自体が表示されません。
234
-
235
- どうやればレスポンスフィールドで得た緯度経度をgooglemapapiのpositionに渡しmarkerを作成して地図を表示できるのかわかりません。
236
-
237
-
238
-
239
- ご教授お願いします。
240
-
241
-
242
-
243
- ```
244
-
245
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
246
-
247
- <html>
248
-
249
- <head>
250
-
251
- <title>Google Maps V3</title>
252
-
253
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
254
-
255
- <script type="text/javascript" src="http://maps.google.com/maps/api/js?&sensor=false"></script>
256
-
257
- <script type="text/javascript">
258
-
259
- google.maps.event.addDomListener(window, 'load', function()
260
-
261
- {
262
-
263
- var lat =35.68944;
264
-
265
- var lng =139.69167 ;
266
-
267
-
268
-
269
- var latlng = new google.maps.LatLng(lat, lng);
270
-
271
- var mapOptions = {
272
-
273
- zoom: 12,
274
-
275
- center: latlng,
276
-
277
- mapTypeId: google.maps.MapTypeId.ROADMAP,
278
-
279
- scaleControl: true
280
-
281
- };
282
-
283
- var mapObj = new google.maps.Map(document.getElementById('gmap'), mapOptions);
284
-
285
-
286
-
287
- var marker = new google.maps.Marker({
288
-
289
- position: {lat: <?= $r->$lat ?>, lng: <?= $r->$lng ?>},
290
-
291
- map: mapObj
292
-
293
- });
294
-
295
- });
296
-
297
- </script>
298
-
299
- ```

1

コードを全文掲示します。

2016/10/12 14:44

投稿

aba623ky
aba623ky

スコア63

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,165 @@
1
+ コードを全文提示します。
2
+
3
+
4
+
5
+ このように書きました。
6
+
7
+ ```
8
+
9
+ <?php
10
+
11
+ $key='My key';
12
+
13
+ $count='10';
14
+
15
+ $large_area='Z014';
16
+
17
+ $start =1;
18
+
19
+ $format='xml';
20
+
21
+ $url='http://webservice.recruit.co.jp/hotpepper/gourmet/v1/?key='.$key.'&count='.$count.'&large_area='.$large_area.'&start='.$start.'&format='.$format;
22
+
23
+ $xml=simplexml_load_file($url);
24
+
25
+ $total_count=$xml->results_available;
26
+
27
+ if(!$xml->shop){
28
+
29
+ echo 'We can not find!!';
30
+
31
+ } else {
32
+
33
+ foreach($xml->shop as $rest){
34
+
35
+ echo '<table border="1">';
36
+
37
+ echo '<tr>';
38
+
39
+ echo '<td>';
40
+
41
+ echo $rest->name;
42
+
43
+ echo '</td>';
44
+
45
+ echo '</tr>';
46
+
47
+ echo '<tr class="map">';
48
+
49
+ echo '<td>';
50
+
51
+ echo $rest->lng;
52
+
53
+ echo $rest->lat;
54
+
55
+ echo '</td>';
56
+
57
+ echo '</tr>';
58
+
59
+ echo '<tr>';
60
+
61
+ echo '<td>';
62
+
63
+ echo $rest->address;
64
+
65
+ echo '</td>';
66
+
67
+ echo '</tr>';
68
+
69
+ echo '</table>';
70
+
71
+
72
+
73
+
74
+
75
+ ?>
76
+
77
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
78
+
79
+ <html>
80
+
81
+ <head>
82
+
83
+ <title>Google Maps V3</title>
84
+
85
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
86
+
87
+ <script type="text/javascript" src="http://maps.google.com/maps/api/js?&sensor=false"></script>
88
+
89
+ <script type="text/javascript">
90
+
91
+ google.maps.event.addDomListener(window, 'load', function()
92
+
93
+ {
94
+
95
+ var lat =35.68944;
96
+
97
+ var lng =139.69167 ;
98
+
99
+
100
+
101
+ var latlng = new google.maps.LatLng(lat, lng);
102
+
103
+ var mapOptions = {
104
+
105
+ zoom: 12,
106
+
107
+ center: latlng,
108
+
109
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
110
+
111
+ scaleControl: true
112
+
113
+ };
114
+
115
+ var mapObj = new google.maps.Map(document.getElementById('gmap'), mapOptions);
116
+
117
+
118
+
119
+ var marker = new google.maps.Marker({
120
+
121
+ position: {lat:$rest->$lat, lng:$rest->$lng },
122
+
123
+ map: mapObj
124
+
125
+ });
126
+
127
+ });
128
+
129
+ </script>
130
+
131
+ </head>
132
+
133
+ <body>
134
+
135
+ <div id="gmap" style="width: 500px; height: 370px; border: 1px solid Gray;">
136
+
137
+ </div>
138
+
139
+ </body>
140
+
141
+ </html>
142
+
143
+ <?php
144
+
145
+ }
146
+
147
+ }
148
+
149
+ ?>
150
+
151
+ ```
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
1
163
  ホットペーパーapiのレスポンスフィールドの$latと$lng (緯度経度)をgoogle map apiにその値を渡し、地図に位置情報を表したいです。
2
164
 
3
165