I have this JSON output:
Array ( [info] => Array ( [statuscode] => 0 [copyright] => Array ( [text] => © 2020 MapQuest, Inc. [imageUrl] => http://api.mqcdn.com/res/mqlogo.gif [imageAltText] => © 2020 MapQuest, Inc. ) [messages] => Array ( ) ) [options] => Array ( [maxResults] => -1 [thumbMaps] => 1 [ignoreLatLngInput] => ) [results] => Array ( [0] => Array ( [providedLocation] => Array ( [location] => dizingof 30 tel aviv ) [locations] => Array ( [0] => Array ( [street] => 30 Dizengoff [adminArea6] => Lev HaIr [adminArea6Type] => Neighborhood [adminArea5] => Tel Aviv-Yafo [adminArea5Type] => City [adminArea4] => [adminArea4Type] => County [adminArea3] => Tel Aviv District [adminArea3Type] => State [adminArea1] => IL [adminArea1Type] => Country [postalCode] => NO [geocodeQualityCode] => P1XXX [geocodeQuality] => POINT [dragPoint] => [sideOfStreet] => N [linkId] => 0 [unknownInput] => [type] => s [latLng] => Array ( [lat] => 32.074559 [lng] => 34.777848 ) [displayLatLng] => Array ( [lat] => 32.074559 [lng] => 34.777848 ) [mapUrl] => http://open.mapquestapi.com/staticmap/v5/map?key=MY-KEY-HIDDEN&type=map&size=225,160&locations=32.074559,34.777848|marker-sm-50318A-1&scalebar=true&zoom=15&rand=1117187015 ) [1] => Array ( [street] => Dizengoff [adminArea6] => Sarona Gardens [adminArea6Type] => Neighborhood [adminArea5] => Tel Aviv-Yafo [adminArea5Type] => City [adminArea4] => [adminArea4Type] => County [adminArea3] => Tel Aviv District [adminArea3Type] => State [adminArea1] => IL [adminArea1Type] => Country [postalCode] => NO [geocodeQualityCode] => B1XXX [geocodeQuality] => STREET [dragPoint] => [sideOfStreet] => N [linkId] => 0 [unknownInput] => [type] => s [latLng] => Array ( [lat] => 32.073606 [lng] => 34.781814 ) [displayLatLng] => Array ( [lat] => 32.073606 [lng] => 34.781814 ) [mapUrl] => http://open.mapquestapi.com/staticmap/v5/map?key=MY-KEY-HIDDEN&type=map&size=225,160&locations=32.0736057,34.7818135|marker-sm-50318A-2&scalebar=true&zoom=15&rand=69101606 ) [2] => Array ( [street] => Dizengoff [adminArea6] => Lev HaIr [adminArea6Type] => Neighborhood [adminArea5] => Tel Aviv-Yafo [adminArea5Type] => City [adminArea4] => [adminArea4Type] => County [adminArea3] => Tel Aviv District [adminArea3Type] => State [adminArea1] => IL [adminArea1Type] => Country [postalCode] => NO [geocodeQualityCode] => B1XXX [geocodeQuality] => STREET [dragPoint] => [sideOfStreet] => N [linkId] => 0 [unknownInput] => [type] => s [latLng] => Array ( [lat] => 32.074859 [lng] => 34.775842 ) [displayLatLng] => Array ( [lat] => 32.074859 [lng] => 34.775842 ) [mapUrl] => http://open.mapquestapi.com/staticmap/v5/map?key=MY-KEY-HIDDEN&type=map&size=225,160&locations=32.0748594,34.7758419|marker-sm-50318A-3&scalebar=true&zoom=15&rand=-770905889 ) [3] => Array ( [street] => Dizengoff [adminArea6] => Kochav HaTsafon [adminArea6Type] => Neighborhood [adminArea5] => Tel Aviv-Yafo [adminArea5Type] => City [adminArea4] => [adminArea4Type] => County [adminArea3] => Tel Aviv District [adminArea3Type] => State [adminArea1] => IL [adminArea1Type] => Country [postalCode] => NO [geocodeQualityCode] => B1XXX [geocodeQuality] => STREET [dragPoint] => [sideOfStreet] => N [linkId] => 0 [unknownInput] => [type] => s [latLng] => Array ( [lat] => 32.095439 [lng] => 34.776301 ) [displayLatLng] => Array ( [lat] => 32.095439 [lng] => 34.776301 ) [mapUrl] => http://open.mapquestapi.com/staticmap/v5/map?key=MY-KEY-HIDDEN&type=map&size=225,160&locations=32.0954392,34.7763013|marker-sm-50318A-4&scalebar=true&zoom=15&rand=-2131033145 ) [4] => Array ( [street] => Dizengoff [adminArea6] => The Old North [adminArea6Type] => Neighborhood [adminArea5] => Tel Aviv-Yafo [adminArea5Type] => City [adminArea4] => [adminArea4Type] => County [adminArea3] => Tel Aviv District [adminArea3Type] => State [adminArea1] => IL [adminArea1Type] => Country [postalCode] => NO [geocodeQualityCode] => B1XXX [geocodeQuality] => STREET [dragPoint] => [sideOfStreet] => N [linkId] => 0 [unknownInput] => [type] => s [latLng] => Array ( [lat] => 32.079132 [lng] => 34.773921 ) [displayLatLng] => Array ( [lat] => 32.079132 [lng] => 34.773921 ) [mapUrl] => http://open.mapquestapi.com/staticmap/v5/map?key=MY-KEY-HIDDEN&type=map&size=225,160&locations=32.0791324,34.773921|marker-sm-50318A-5&scalebar=true&zoom=15&rand=130107888 ) [5] => Array ( [street] => [adminArea6] => Sarona Gardens [adminArea6Type] => Neighborhood [adminArea5] => Tel Aviv-Yafo [adminArea5Type] => City [adminArea4] => [adminArea4Type] => County [adminArea3] => Tel Aviv District [adminArea3Type] => State [adminArea1] => IL [adminArea1Type] => Country [postalCode] => NO [geocodeQualityCode] => B1XXX [geocodeQuality] => STREET [dragPoint] => [sideOfStreet] => N [linkId] => 0 [unknownInput] => [type] => s [latLng] => Array ( [lat] => 32.073517 [lng] => 34.781844 ) [displayLatLng] => Array ( [lat] => 32.073517 [lng] => 34.781844 ) [mapUrl] => http://open.mapquestapi.com/staticmap/v5/map?key=MY-KEY-HIDDEN&type=map&size=225,160&locations=32.0735171,34.7818443|marker-sm-50318A-6&scalebar=true&zoom=15&rand=1411286189 ) ) ) ) )
or…
{"info":{"statuscode":0,"copyright":{"text":"u00A9 2020 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"u00A9 2020 MapQuest, Inc."},"messages":[]},"options":{"maxResults":-1,"thumbMaps":true,"ignoreLatLngInput":false},"results":[{"providedLocation":{"location":"dizingof 30 tel aviv"},"locations":[{"street":"30 Dizengoff","adminArea6":"Lev HaIr","adminArea6Type":"Neighborhood","adminArea5":"Tel Aviv-Yafo","adminArea5Type":"City","adminArea4":"","adminArea4Type":"County","adminArea3":"Tel Aviv District","adminArea3Type":"State","adminArea1":"IL","adminArea1Type":"Country","postalCode":"NO","geocodeQualityCode":"P1XXX","geocodeQuality":"POINT","dragPoint":false,"sideOfStreet":"N","linkId":"0","unknownInput":"","type":"s","latLng":{"lat":32.074559,"lng":34.777848},"displayLatLng":{"lat":32.074559,"lng":34.777848},"mapUrl":"http://open.mapquestapi.com/staticmap/v5/map?key=aem9j0suA3OtGfn3Ww3eWfMh8PkxwdPO&type=map&size=225,160&locations=32.074559,34.777848|marker-sm-50318A-1&scalebar=true&zoom=15&rand=2104114146"},{"street":"Dizengoff","adminArea6":"Sarona Gardens","adminArea6Type":"Neighborhood","adminArea5":"Tel Aviv-Yafo","adminArea5Type":"City","adminArea4":"","adminArea4Type":"County","adminArea3":"Tel Aviv District","adminArea3Type":"State","adminArea1":"IL","adminArea1Type":"Country","postalCode":"NO","geocodeQualityCode":"B1XXX","geocodeQuality":"STREET","dragPoint":false,"sideOfStreet":"N","linkId":"0","unknownInput":"","type":"s","latLng":{"lat":32.073606,"lng":34.781814},"displayLatLng":{"lat":32.073606,"lng":34.781814},"mapUrl":"http://open.mapquestapi.com/staticmap/v5/map?key=aem9j0suA3OtGfn3Ww3eWfMh8PkxwdPO&type=map&size=225,160&locations=32.0736057,34.7818135|marker-sm-50318A-2&scalebar=true&zoom=15&rand=1683341942"},{"street":"Dizengoff","adminArea6":"Lev HaIr","adminArea6Type":"Neighborhood","adminArea5":"Tel Aviv-Yafo","adminArea5Type":"City","adminArea4":"","adminArea4Type":"County","adminArea3":"Tel Aviv District","adminArea3Type":"State","adminArea1":"IL","adminArea1Type":"Country","postalCode":"NO","geocodeQualityCode":"B1XXX","geocodeQuality":"STREET","dragPoint":false,"sideOfStreet":"N","linkId":"0","unknownInput":"","type":"s","latLng":{"lat":32.074859,"lng":34.775842},"displayLatLng":{"lat":32.074859,"lng":34.775842},"mapUrl":"http://open.mapquestapi.com/staticmap/v5/map?key=aem9j0suA3OtGfn3Ww3eWfMh8PkxwdPO&type=map&size=225,160&locations=32.0748594,34.7758419|marker-sm-50318A-3&scalebar=true&zoom=15&rand=-2088802316"},{"street":"Dizengoff","adminArea6":"Kochav HaTsafon","adminArea6Type":"Neighborhood","adminArea5":"Tel Aviv-Yafo","adminArea5Type":"City","adminArea4":"","adminArea4Type":"County","adminArea3":"Tel Aviv District","adminArea3Type":"State","adminArea1":"IL","adminArea1Type":"Country","postalCode":"NO","geocodeQualityCode":"B1XXX","geocodeQuality":"STREET","dragPoint":false,"sideOfStreet":"N","linkId":"0","unknownInput":"","type":"s","latLng":{"lat":32.095439,"lng":34.776301},"displayLatLng":{"lat":32.095439,"lng":34.776301},"mapUrl":"http://open.mapquestapi.com/staticmap/v5/map?key=aem9j0suA3OtGfn3Ww3eWfMh8PkxwdPO&type=map&size=225,160&locations=32.0954392,34.7763013|marker-sm-50318A-4&scalebar=true&zoom=15&rand=2124721012"},{"street":"Dizengoff","adminArea6":"The Old North","adminArea6Type":"Neighborhood","adminArea5":"Tel Aviv-Yafo","adminArea5Type":"City","adminArea4":"","adminArea4Type":"County","adminArea3":"Tel Aviv District","adminArea3Type":"State","adminArea1":"IL","adminArea1Type":"Country","postalCode":"NO","geocodeQualityCode":"B1XXX","geocodeQuality":"STREET","dragPoint":false,"sideOfStreet":"N","linkId":"0","unknownInput":"","type":"s","latLng":{"lat":32.079132,"lng":34.773921},"displayLatLng":{"lat":32.079132,"lng":34.773921},"mapUrl":"http://open.mapquestapi.com/staticmap/v5/map?key=aem9j0suA3OtGfn3Ww3eWfMh8PkxwdPO&type=map&size=225,160&locations=32.0791324,34.773921|marker-sm-50318A-5&scalebar=true&zoom=15&rand=124836944"},{"street":"","adminArea6":"Sarona Gardens","adminArea6Type":"Neighborhood","adminArea5":"Tel Aviv-Yafo","adminArea5Type":"City","adminArea4":"","adminArea4Type":"County","adminArea3":"Tel Aviv District","adminArea3Type":"State","adminArea1":"IL","adminArea1Type":"Country","postalCode":"NO","geocodeQualityCode":"B1XXX","geocodeQuality":"STREET","dragPoint":false,"sideOfStreet":"N","linkId":"0","unknownInput":"","type":"s","latLng":{"lat":32.073517,"lng":34.781844},"displayLatLng":{"lat":32.073517,"lng":34.781844},"mapUrl":"http://open.mapquestapi.com/staticmap/v5/map?key=aem9j0suA3OtGfn3Ww3eWfMh8PkxwdPO&type=map&size=225,160&locations=32.0735171,34.7818443|marker-sm-50318A-6&scalebar=true&zoom=15&rand=237130537"}]}]}
I’m trying to print specific data:
locations -> latLng -> lat
So my output will be: 32.074559
I’ve tried this:
$json = file_get_contents('THE API URL'); $obj = json_decode($json, true); echo $obj['locations']['latLng']['lat'];
But it’s not working, show nothing…
Advertisement
Answer
Her is a working example:
echo $obj['results'][0]['locations'][0]['latLng']['lat'];
Output:
32.074559