Extract all fields from XML result using Google Geocoding API

Arrillabiva

New Member
I am using the Google Geocoding API, specifically relying on the XML output format. The code below loops through the array \[code\]$arrGeocodeSales\[/code\] and for each row it retrieves the \[code\]$lat\[/code\] and \[code\]$long\[/code\], which are then displayed in the table.This code is working fine, but I would like to extend it so that I can extract more fields from the \[code\]$xml\[/code\] result that is returned. For example, some of the additional fields that I would like to extract from the $xml result are \[code\]formatted_address\[/code\] and \[code\]postal_code\[/code\]. How can I modify the code below to extract the additional fields?You can see an example of an $xml result here:http://maps.googleapis.com/maps/api...heatre Parkway, Mountain View, CA&sensor=trueHere is the code that needs to be modified. I guess I don't understand how to work with the \[code\]SimpleXMLElement\[/code\] that is returned. Thanks for the help.\[code\]<table border="1" style="margin-bottom:0px;"><tr> <th>ID</th> <th>Roll</th> <th>Address</th> <th>Lat</th> <th>Long</th> <th>MapSaleNumber</th> </tr><?php foreach ($arrGeocodeSales as $key => $value): $address = $value['Address']."+".$value['Municipality']."+Ontario+Canada"; $googleAddress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml"; // Retrieve the URL contents $googlePage = file_get_contents($googleAddress); // Parse the returned XML file $xml = new SimpleXMLElement($googlePage); // Parse the coordinate string list($lng, $lat, $alt) = explode(",", $xml->Response->Placemark->Point->coordinates); ?><tr> <td ><?php echo str_pad($row++, 2, '0', STR_PAD_LEFT); ?></td> <td ><?php echo $value['SingleRoll']; ?></td> <td ><?php echo $address; ?> </td> <td ><?php echo $lat ?></td> <td ><?php echo $lng ?></td> <td ><?php echo $value['MapSaleNumber']; ?></td> </tr><?php endforeach; ?>\[/code\]
 
Back
Top