質問編集履歴
1
指示いただいたコードを追加した結果
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,4 +18,41 @@
|
|
18
18
|
var_dump($de_json);
|
19
19
|
echo '<hr>';
|
20
20
|
|
21
|
-
```
|
21
|
+
```
|
22
|
+
|
23
|
+
ご指摘いただき下記のように修正しました。
|
24
|
+
```
|
25
|
+
|
26
|
+
$url ="https://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat.",".$lng."&language=ja&key=".$g_key;
|
27
|
+
$json = file_get_contents($url);
|
28
|
+
|
29
|
+
echo json_encode($json);
|
30
|
+
|
31
|
+
$json_de = json_decode($json);
|
32
|
+
|
33
|
+
//echo 'de_j:'.$de_json->{'results'};
|
34
|
+
//// $decoded_jsonからデータを取り出して表示します。
|
35
|
+
print($json_de->{"c"});
|
36
|
+
|
37
|
+
|
38
|
+
//echo json_encode($json_de,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
39
|
+
echo '<hr>';
|
40
|
+
//var_dump($de_json);
|
41
|
+
//echo '<hr>';
|
42
|
+
|
43
|
+
|
44
|
+
foreach (json_decode($json)->results as $result) {
|
45
|
+
echo 'lat:' . $result->geometry->location->lat . ', lng:' . $result->geometry->location->lng . PHP_EOL;
|
46
|
+
}
|
47
|
+
```
|
48
|
+
出力結果:東京タワー
|
49
|
+
東京タワーでlat,lngを取得し、逆コーディングで住所を取得したいのですが
|
50
|
+
見にくく要素が分かりません。
|
51
|
+
どのようなコードだとわかりやすくなるのでしょうか。。
|
52
|
+
---
|
53
|
+
"{\n \"plus_code\" : {\n \"compound_code\" : \"MP5W+C5 \u65e5\u672c\u3001\u6771\u4eac\u90fd\u6771\u4eac\",\n \"global_code\" : \"8Q7XMP5W+C5\"\n },\n \"results\" : [\n {\n \"address_components\" : [\n {\n \"long_name\" : \"\uff18\",\n \"short_name\" : \"\uff18\",\n \"types\" : [ \"premise\" ]\n },\n {\n \"long_name\" : \"\uff12\",\n \"short_name\" : \"\uff12\",\n \"types\" : [ \"political\", \"sublocality\", \"sublocality_level_4\" ]\n },\n {\n \"long_name\" : \"\uff14\u4e01\u76ee\",\n \"short_name\" : \"\uff14\u4e01\u76ee\",\n \"types\" : [ \"political\", \"sublocality\", \"sublocality_level_3\" ]\n },\n {\n \"long_name\" : \"\u829d\u516c\u5712\",\n \"short_name\" : \"\u829d\u516c\u5712\",\n \"types\" : [ \"political\", \"sublocality\", \"sublocality_level_2\" ]\n },\n {\n \"long_name\" : \"\u6e2f\u533a\",\n \"short_name\" : \"\u6e2f\u533a\",\n \"types\" : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\" : \"\u6771\u4eac\u90fd\",\n \"short_name\" : \"\u6771\u4eac\u90fd\",\n \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n },\n {\n \"long_name\" : \"\u65e5\u672c\",\n \"short_name\" : \"JP\",\n \"types\" : [ \"country\", \"political\" ]\n },\n {\n \"long_name\" : \"105-0011\",\n \"short_name\" :
|
54
|
+
|
55
|
+
途中略
|
56
|
+
|
57
|
+
20.3585295,\n \"lng\" : 122.8554688\n }\n },\n \"location\" : {\n \"lat\" : 36.204824,\n \"lng\" : 138.252924\n },\n \"location_type\" : \"APPROXIMATE\",\n \"viewport\" : {\n \"northeast\" : {\n \"lat\" : 45.6412626,\n \"lng\" : 154.0031455\n },\n \"southwest\" : {\n \"lat\" : 20.3585295,\n \"lng\" : 122.8554688\n }\n }\n },\n \"place_id\" : \"ChIJLxl_1w9OZzQRRFJmfNR1QvU\",\n \"types\" : [ \"country\", \"political\" ]\n }\n ],\n \"status\" : \"OK\"\n}\n"
|
58
|
+
lat:35.6585805, lng:139.7454329 lat:35.6585769, lng:139.7454506 lat:35.6585453, lng:139.7452445 lat:35.6563336, lng:139.7479592 lat:35.6571637, lng:139.7485979 lat:35.6571637, lng:139.7485979 lat:35.6580813, lng:139.7515077 lat:35.6803997, lng:139.7690174 lat:35.6761919, lng:139.6503106 lat:36.204824, lng:138.252924 gmads:Array
|