Ik ben bezig om via de Google Maps API een adres om te zetten naar Latitude/Longitude.
Nou lukt dat wel aardig, enkel het uitlezen van de JSON lukt me nog niet helemaal.
Ik heb het volgende:
<?php
public function getGeolocation($zipcode, $city) {
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $zipcode . "," . $city . "&sensor=false";
$content = file_get_contents($url);
$geo = var_dump(json_decode($content, TRUE));
return $geo['geometry'];
}
?>
En dan zit in $geo het volgende:
array(2) {
6 ["status"]=>
7 string(2) "OK"
8 ["results"]=>
9 array(1) {
10 [0]=>
11 array(4) {
12 ["types"]=>
13 array(1) {
14 [0]=>
15 string(11) "postal_code"
16 }
17 ["formatted_address"]=>
18 string(36) "xxxx xx xxxxxx, The Netherlands"
19 ["address_components"]=>
20 array(5) {
21 [0]=>
22 array(3) {
23 ["long_name"]=>
24 string(7) "xxxx xx"
25 ["short_name"]=>
26 string(7) "xxxx xx"
27 ["types"]=>
28 array(1) {
29 [0]=>
30 string(11) "postal_code"
31 }
32 }
33 [1]=>
34 array(3) {
35 ["long_name"]=>
36 string(11) "xxxxxx"
37 ["short_name"]=>
38 string(11) "xxxxxx"
39 ["types"]=>
40 array(2) {
41 [0]=>
42 string(8) "locality"
43 [1]=>
44 string(9) "political"
45 }
46 }
47 [2]=>
48 array(3) {
49 ["long_name"]=>
50 string(15) "xxxxxx"
51 ["short_name"]=>
52 string(15) "xxxxxx"
53 ["types"]=>
54 array(2) {
55 [0]=>
56 string(27) "administrative_area_level_2"
57 [1]=>
58 string(9) "political"
59 }
60 }
61 [3]=>
62 array(3) {
63 ["long_name"]=>
64 string(9) "Friesland"
65 ["short_name"]=>
66 string(2) "FR"
67 ["types"]=>
68 array(2) {
69 [0]=>
70 string(27) "administrative_area_level_1"
71 [1]=>
72 string(9) "political"
73 }
74 }
75 [4]=>
76 array(3) {
77 ["long_name"]=>
78 string(15) "The Netherlands"
79 ["short_name"]=>
80 string(2) "NL"
81 ["types"]=>
82 array(2) {
83 [0]=>
84 string(7) "country"
85 [1]=>
86 string(9) "political"
87 }
88 }
89 }
90 ["geometry"]=>
91 array(3) {
92 ["location"]=>
93 array(2) {
94 ["lat"]=>
95 float(00.0000000)
96 ["lng"]=>
97 float(0.0000000)
98 }
99 ["location_type"]=>
100 string(11) "APPROXIMATE"
101 ["viewport"]=>
102 array(2) {
103 ["southwest"]=>
104 array(2) {
105 ["lat"]=>
106 float(00.0000000)
107 ["lng"]=>
108 float(0.0000000)
109 }
110 ["northeast"]=>
111 array(2) {
112 ["lat"]=>
113 float(00.0000000)
114 ["lng"]=>
115 float(0.0000000)
116 }
117 }
118 }
119 }
120 }
121}
Nu is het de bedoeling dat ik de waardes lat en long uit Geometry->location->lat/long haal. Het enige probleem is is dat het me niet lukt. Ik krijg het niet voor elkaar om uit zo iets gegevens te halen, terwijl het niks anders is dan een associative array? Kan iemand mij op de goede weg helpen?
4.708 views