teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

?の全角を半角に修正

2020/04/07 06:46

投稿

prosal
prosal

スコア17

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
  よろしくお願いします。
4
4
 
5
5
  ```ここに言語を入力
6
- $url ="https://maps.googleapis.com/maps/api/geocode/jsonlatlng=".$lat.",".$lng."&key=".$g_key;
6
+ $url ="https://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat.",".$lng."&key=".$g_key;
7
7
  $json = file_get_contents($url);
8
8
 
9
9
  echo 'json:'.$json.'<P>';

2

key付きのものにしました

2020/04/07 06:45

投稿

prosal
prosal

スコア17

title CHANGED
File without changes
body CHANGED
@@ -38,4 +38,33 @@
38
38
  print_r($addresses);
39
39
  print('</pre>');
40
40
 
41
+ ```
42
+
43
+ keyを足しました
44
+ ```ここに言語を入力
45
+ $latlngs = array();
46
+ $latlngs = [
47
+ ['35.7202869', '139.9249688'],
48
+ ['35.71148684139082', '139.76839363574982'],
49
+ ['35.72546314632721', '139.7471398115158'],
50
+ ['35.738426818811796', '139.73446369171143'],
51
+ ['35.76239773757285', '139.74768161773682']
52
+ ];
53
+ /*
54
+ ** jsonデータ取得
55
+ */
56
+ $GMADs = array();
57
+ foreach ($latlngs as $latlng) {
58
+ $GMADs[] = json_decode(@file_get_contents('http://maps.google.com/maps/api/geocode/json?latlng=' . $latlng[0] . ',' . $latlng[1] . '&sensor=false&language=ja'."&key=".$g_key), true);
59
+ }
60
+ /*
61
+ ** 住所取得
62
+ */
63
+ $addresses = array();
64
+ foreach ($GMADs as $GMAD) {
65
+ $addresses[] = $GMAD['results'][0]['formatted_address'];
66
+ }
67
+ print('<pre>');
68
+ print_r($addresses);
69
+ print('</pre>');
41
70
  ```

1

テストしたコードを追加

2020/04/07 06:36

投稿

prosal
prosal

スコア17

title CHANGED
File without changes
body CHANGED
@@ -7,4 +7,35 @@
7
7
  $json = file_get_contents($url);
8
8
 
9
9
  echo 'json:'.$json.'<P>';
10
+ ```
11
+
12
+ テストとして下記を実施しましたが取得できませんでした。
13
+ ```ここに言語を入力
14
+
15
+ $latlngs = array();
16
+ $latlngs = [
17
+ ['35.7202869', '139.9249688'],
18
+ ['35.71148684139082', '139.76839363574982'],
19
+ ['35.72546314632721', '139.7471398115158'],
20
+ ['35.738426818811796', '139.73446369171143'],
21
+ ['35.76239773757285', '139.74768161773682']
22
+ ];
23
+ /*
24
+ ** jsonデータ取得
25
+ */
26
+ $GMADs = array();
27
+ foreach ($latlngs as $latlng) {
28
+ $GMADs[] = json_decode(@file_get_contents('http://maps.google.com/maps/api/geocode/json?latlng=' . $latlng[0] . ',' . $latlng[1] . '&sensor=false&language=ja'."&key=".$g_key), true);
29
+ }
30
+ /*
31
+ ** 住所取得
32
+ */
33
+ $addresses = array();
34
+ foreach ($GMADs as $GMAD) {
35
+ $addresses[] = $GMAD['results'][0]['formatted_address'];
36
+ }
37
+ print('<pre>');
38
+ print_r($addresses);
39
+ print('</pre>');
40
+
10
41
  ```