質問編集履歴

3

?の全角を半角に修正

2020/04/07 06:46

投稿

prosal
prosal

スコア17

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ```ここに言語を入力
10
10
 
11
- $url ="https://maps.googleapis.com/maps/api/geocode/jsonlatlng=".$lat.",".$lng."&key=".$g_key;
11
+ $url ="https://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat.",".$lng."&key=".$g_key;
12
12
 
13
13
  $json = file_get_contents($url);
14
14
 

2

key付きのものにしました

2020/04/07 06:45

投稿

prosal
prosal

スコア17

test CHANGED
File without changes
test CHANGED
@@ -79,3 +79,61 @@
79
79
 
80
80
 
81
81
  ```
82
+
83
+
84
+
85
+ keyを足しました
86
+
87
+ ```ここに言語を入力
88
+
89
+ $latlngs = array();
90
+
91
+ $latlngs = [
92
+
93
+ ['35.7202869', '139.9249688'],
94
+
95
+ ['35.71148684139082', '139.76839363574982'],
96
+
97
+ ['35.72546314632721', '139.7471398115158'],
98
+
99
+ ['35.738426818811796', '139.73446369171143'],
100
+
101
+ ['35.76239773757285', '139.74768161773682']
102
+
103
+ ];
104
+
105
+ /*
106
+
107
+ ** jsonデータ取得
108
+
109
+ */
110
+
111
+ $GMADs = array();
112
+
113
+ foreach ($latlngs as $latlng) {
114
+
115
+ $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);
116
+
117
+ }
118
+
119
+ /*
120
+
121
+ ** 住所取得
122
+
123
+ */
124
+
125
+ $addresses = array();
126
+
127
+ foreach ($GMADs as $GMAD) {
128
+
129
+ $addresses[] = $GMAD['results'][0]['formatted_address'];
130
+
131
+ }
132
+
133
+ print('<pre>');
134
+
135
+ print_r($addresses);
136
+
137
+ print('</pre>');
138
+
139
+ ```

1

テストしたコードを追加

2020/04/07 06:36

投稿

prosal
prosal

スコア17

test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,65 @@
17
17
  echo 'json:'.$json.'<P>';
18
18
 
19
19
  ```
20
+
21
+
22
+
23
+ テストとして下記を実施しましたが取得できませんでした。
24
+
25
+ ```ここに言語を入力
26
+
27
+
28
+
29
+ $latlngs = array();
30
+
31
+ $latlngs = [
32
+
33
+ ['35.7202869', '139.9249688'],
34
+
35
+ ['35.71148684139082', '139.76839363574982'],
36
+
37
+ ['35.72546314632721', '139.7471398115158'],
38
+
39
+ ['35.738426818811796', '139.73446369171143'],
40
+
41
+ ['35.76239773757285', '139.74768161773682']
42
+
43
+ ];
44
+
45
+ /*
46
+
47
+ ** jsonデータ取得
48
+
49
+ */
50
+
51
+ $GMADs = array();
52
+
53
+ foreach ($latlngs as $latlng) {
54
+
55
+ $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);
56
+
57
+ }
58
+
59
+ /*
60
+
61
+ ** 住所取得
62
+
63
+ */
64
+
65
+ $addresses = array();
66
+
67
+ foreach ($GMADs as $GMAD) {
68
+
69
+ $addresses[] = $GMAD['results'][0]['formatted_address'];
70
+
71
+ }
72
+
73
+ print('<pre>');
74
+
75
+ print_r($addresses);
76
+
77
+ print('</pre>');
78
+
79
+
80
+
81
+ ```