回答編集履歴
1
サンプルコードを追加
test
CHANGED
@@ -1,3 +1,151 @@
|
|
1
1
|
resultsってArrayで返ってくるから、
|
2
2
|
|
3
3
|
foreach()ループを回すなりしたらいいんじゃないかとー。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```php
|
8
|
+
|
9
|
+
<?php
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
$json = <<<EOT
|
14
|
+
|
15
|
+
{
|
16
|
+
|
17
|
+
"results" : [
|
18
|
+
|
19
|
+
{
|
20
|
+
|
21
|
+
"address_components" : [
|
22
|
+
|
23
|
+
{
|
24
|
+
|
25
|
+
"long_name" : "1600",
|
26
|
+
|
27
|
+
"short_name" : "1600",
|
28
|
+
|
29
|
+
"types" : [ "street_number" ]
|
30
|
+
|
31
|
+
},
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
"long_name" : "Amphitheatre Pkwy",
|
36
|
+
|
37
|
+
"short_name" : "Amphitheatre Pkwy",
|
38
|
+
|
39
|
+
"types" : [ "route" ]
|
40
|
+
|
41
|
+
},
|
42
|
+
|
43
|
+
{
|
44
|
+
|
45
|
+
"long_name" : "Mountain View",
|
46
|
+
|
47
|
+
"short_name" : "Mountain View",
|
48
|
+
|
49
|
+
"types" : [ "locality", "political" ]
|
50
|
+
|
51
|
+
},
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
"long_name" : "Santa Clara County",
|
56
|
+
|
57
|
+
"short_name" : "Santa Clara County",
|
58
|
+
|
59
|
+
"types" : [ "administrative_area_level_2", "political" ]
|
60
|
+
|
61
|
+
},
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
"long_name" : "California",
|
66
|
+
|
67
|
+
"short_name" : "CA",
|
68
|
+
|
69
|
+
"types" : [ "administrative_area_level_1", "political" ]
|
70
|
+
|
71
|
+
},
|
72
|
+
|
73
|
+
{
|
74
|
+
|
75
|
+
"long_name" : "United States",
|
76
|
+
|
77
|
+
"short_name" : "US",
|
78
|
+
|
79
|
+
"types" : [ "country", "political" ]
|
80
|
+
|
81
|
+
},
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
"long_name" : "94043",
|
86
|
+
|
87
|
+
"short_name" : "94043",
|
88
|
+
|
89
|
+
"types" : [ "postal_code" ]
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
],
|
94
|
+
|
95
|
+
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
|
96
|
+
|
97
|
+
"geometry" : {
|
98
|
+
|
99
|
+
"location" : {
|
100
|
+
|
101
|
+
"lat" : 37.4224764,
|
102
|
+
|
103
|
+
"lng" : -122.0842499
|
104
|
+
|
105
|
+
},
|
106
|
+
|
107
|
+
"location_type" : "ROOFTOP",
|
108
|
+
|
109
|
+
"viewport" : {
|
110
|
+
|
111
|
+
"northeast" : {
|
112
|
+
|
113
|
+
"lat" : 37.4238253802915,
|
114
|
+
|
115
|
+
"lng" : -122.0829009197085
|
116
|
+
|
117
|
+
},
|
118
|
+
|
119
|
+
"southwest" : {
|
120
|
+
|
121
|
+
"lat" : 37.4211274197085,
|
122
|
+
|
123
|
+
"lng" : -122.0855988802915
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
},
|
130
|
+
|
131
|
+
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
|
132
|
+
|
133
|
+
"types" : [ "street_address" ]
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
],
|
138
|
+
|
139
|
+
"status" : "OK"
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
EOT;
|
144
|
+
|
145
|
+
foreach (json_decode($json)->results as $result) {
|
146
|
+
|
147
|
+
echo 'lat:' . $result->geometry->location->lat . ', lng:' . $result->geometry->location->lng . PHP_EOL;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
```
|