apiKey; $nsKml = 'http://earth.google.com/kml/2.0'; $nsUrn = 'urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'; $file = $this->loadXML( $url ); if( empty( $file ) ) { return $retVal; } $retVal['Response'] = array( 'Status' => (int)$file['response'], 'Request' => 'geo' ); if( $file['response'] == 200 ) { $xml = new SimpleXMLElement( $file['contents'] ); $xml->registerXPathNamespace( 'kml', $nsKml ); $xml->registerXPathNamespace( 'urn', $nsUrn ); //Now that we have the google request, and we succeeded in getting a response //from the server, lets replace oure response portion with the google response $retVal['Response']['Status'] = (int)$xml->Response->Status->code; $retVal['Response']['Request'] = (string)$xml->Response->Status->request; $retVal['Placemarks'] = array(); if( $xml && $retVal['Response']['Status'] == GoogleGeocode::SUCCESS ) { $placemarks = $xml->xpath('//kml:Placemark'); $countries = $xml->xpath('//urn:CountryNameCode'); $adminAreas = $xml->xpath('//urn:AdministrativeAreaName'); $subAdminAreas = $xml->xpath('//urn:SubAdministrativeAreaName'); $localities = $xml->xpath('//urn:LocalityName'); $thoroughfares = $xml->xpath('//urn:ThoroughfareName'); $postalCodes = $xml->xpath('//urn:PostalCodeNumber'); for( $i = 0; $i < count( $placemarks ); $i++ ) { list($longitude, $latitude) = explode( ',' , $placemarks[$i]->Point->coordinates ); $attributes = $placemarks[$i]->AddressDetails->attributes(); $retVal['Placemarks'][$i] = array(); $retVal['Placemarks'][$i]['Accuracy'] = (int)$attributes['Accuracy']; $retVal['Placemarks'][$i]['Country'] = (string)$countries[$i]; if( count( $adminAreas ) > $i ) { $retVal['Placemarks'][$i]['AdministrativeArea'] = (string)$adminAreas[$i]; } if( count( $subAdminAreas ) > $i ) { $retVal['Placemarks'][$i]['SubAdministrativeArea'] = (string)$subAdminAreas[$i]; } if( count( $localities ) > $i ) { $retVal['Placemarks'][$i]['Locality'] = (string)$localities[$i]; } if( count( $thoroughfares ) > $i ) { $retVal['Placemarks'][$i]['Thoroughfare'] = (string)$thoroughfares[$i]; } if( count( $postalCodes ) > $i ) { $retVal['Placemarks'][$i]['PostalCode'] = (int)$postalCodes[$i]; } $retVal['Placemarks'][$i]['Latitude']= (double)$latitude; $retVal['Placemarks'][$i]['Longitude'] = (double)$longitude; } } } return $retVal; } } ?>