apiKey; $file = $this->loadXML( $request ); if( empty( $file ) ) { return $retVal; } $retVal['Response'] = array( 'Status' => $file['response'], 'Request' => 'geocode' ); if( $retVal['Response']['Status'] == YahooGeocode::SUCCESS ) { $xml = new SimpleXMLElement( $file['contents'] ); $xml->registerXPathNamespace('urn','urn:yahoo:maps'); $retVal['Placemarks'] = array(); if( $xml ) { $results = $xml->xpath('//urn:Result'); $countries = $xml->xpath('//urn:Country'); $adminAreas = $xml->xpath('//urn:State'); //Yahoo Geocoding has no Sub-Administrative Area (County) support. $localities = $xml->xpath('//urn:City'); $thoroughfares = $xml->xpath('//urn:Address'); $postalCodes = $xml->xpath('//urn:Zip'); $latitudes = $xml->xpath('//urn:Latitude'); $longitudes = $xml->xpath('//urn:Longitude'); if( $results ) { for( $i = 0; $i < count( $results ); $i++ ) { $attributes = $results[$i]->attributes(); $retVal['Placemarks'][$i]['Accuracy'] = (string)$attributes['precision']; $retVal['Placemarks'][$i]['Country'] = (string)$countries[$i]; if( count($adminAreas) > $i && !empty($adminAreas[$i]) ) { $retVal['Placemarks'][$i]['AdministrativeArea'] = (string) $adminAreas[$i]; } if( count($localities) > $i && !empty($localities[$i]) ) { $retVal['Placemarks'][$i]['Locality'] = (string) $localities[$i]; } if( count($thoroughfares) > $i && !empty($thoroughfares[$i]) ) { $retVal['Placemarks'][$i]['Thoroughfare'] = (string) $thoroughfares[$i]; } if( count($postalCodes) > $i && !empty($postalCodes[$i]) ) { $postalCode = explode( '-', $postalCodes[$i] ); $retVal['Placemarks'][$i]['PostalCode'] = (int) $postalCode[0]; } $retVal['Placemarks'][$i]['Latitude'] = (double)$latitudes[$i]; $retVal['Placemarks'][$i]['Longitude'] = (double)$longitudes[$i]; } } } } return $retVal; } } ?>