schwim wrote: but am having issues retrieving the values from the json object.
$coordsNode = explode(',', $data->Response->Placemark->Point->coordinates);
Since you've asked for the json to be decoded as an associative array, you'll need to update how you get elements out of $data - it's an array, not an object.
Incidentally, the URLs you give don't return data that matches the structure implied by that line:
<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
<status>OK</status>
<result>
<type>locality</type>
<type>political</type>
<formatted_address>New York, NY, USA</formatted_address>
<address_component>
<long_name>New York</long_name>
<short_name>New York</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>New York</long_name>
<short_name>NY</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>40.7143528</lat>
<lng>-74.0059731</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>40.4959143</lat>
<lng>-74.2557349</lng>
</southwest>
<northeast>
<lat>40.9152414</lat>
<lng>-73.7002721</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>40.4959080</lat>
<lng>-74.2590879</lng>
</southwest>
<northeast>
<lat>40.9152414</lat>
<lng>-73.7002721</lng>
</northeast>
</bounds>
</geometry>
</result>
<result>
<type>colloquial_area</type>
<type>political</type>
<formatted_address>New York metropolitan area, USA</formatted_address>
<address_component>
<long_name>New York metropolitan area</long_name>
<short_name>New York metropolitan area</short_name>
<type>colloquial_area</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>40.9590293</lat>
<lng>-74.0300122</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>39.4985330</lat>
<lng>-75.3585939</lng>
</southwest>
<northeast>
<lat>41.6018065</lat>
<lng>-71.8562140</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>39.4985330</lat>
<lng>-75.3585939</lng>
</southwest>
<northeast>
<lat>41.6018065</lat>
<lng>-71.8562140</lng>
</northeast>
</bounds>
</geometry>
</result>
</GeocodeResponse>
{
"results" : [
{
"address_components" : [
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New York, NY, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.91524140,
"lng" : -73.70027209999999
},
"southwest" : {
"lat" : 40.4959080,
"lng" : -74.25908790
}
},
"location" : {
"lat" : 40.71435280,
"lng" : -74.00597309999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.91524140,
"lng" : -73.70027209999999
},
"southwest" : {
"lat" : 40.49591430,
"lng" : -74.25573489999999
}
}
},
"postcode_localities" : [],
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "New York metropolitan area",
"short_name" : "New York metropolitan area",
"types" : [ "colloquial_area", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New York metropolitan area, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 41.60180650,
"lng" : -71.85621399999999
},
"southwest" : {
"lat" : 39.49853299999999,
"lng" : -75.35859390
}
},
"location" : {
"lat" : 40.95902930,
"lng" : -74.03001220
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 41.60180650,
"lng" : -71.85621399999999
},
"southwest" : {
"lat" : 39.49853299999999,
"lng" : -75.35859390
}
}
},
"postcode_localities" : [],
"types" : [ "colloquial_area", "political" ]
}
],
"status" : "OK"
}