質問編集履歴

1

指示いただいたコードを追加した結果

2020/04/09 06:54

投稿

prosal
prosal

スコア17

test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,77 @@
39
39
 
40
40
 
41
41
  ```
42
+
43
+
44
+
45
+ ご指摘いただき下記のように修正しました。
46
+
47
+ ```
48
+
49
+
50
+
51
+ $url ="https://maps.googleapis.com/maps/api/geocode/json?latlng=".$lat.",".$lng."&language=ja&key=".$g_key;
52
+
53
+ $json = file_get_contents($url);
54
+
55
+
56
+
57
+ echo json_encode($json);
58
+
59
+
60
+
61
+ $json_de = json_decode($json);
62
+
63
+
64
+
65
+ //echo 'de_j:'.$de_json->{'results'};
66
+
67
+ //// $decoded_jsonからデータを取り出して表示します。
68
+
69
+ print($json_de->{"c"});
70
+
71
+
72
+
73
+
74
+
75
+ //echo json_encode($json_de,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
76
+
77
+ echo '<hr>';
78
+
79
+ //var_dump($de_json);
80
+
81
+ //echo '<hr>';
82
+
83
+
84
+
85
+
86
+
87
+ foreach (json_decode($json)->results as $result) {
88
+
89
+ echo 'lat:' . $result->geometry->location->lat . ', lng:' . $result->geometry->location->lng . PHP_EOL;
90
+
91
+ }
92
+
93
+ ```
94
+
95
+ 出力結果:東京タワー
96
+
97
+ 東京タワーでlat,lngを取得し、逆コーディングで住所を取得したいのですが
98
+
99
+ 見にくく要素が分かりません。
100
+
101
+ どのようなコードだとわかりやすくなるのでしょうか。。
102
+
103
+ ---
104
+
105
+ "{\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\" :
106
+
107
+
108
+
109
+ 途中略
110
+
111
+
112
+
113
+ 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"
114
+
115
+ 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