Пример #1
0
 /**
  * Parse the XML result
  * The return array returns the following information
  *
  *      'accuracy' - the Accuracy constant as found in {@link GeoCode_Driver_Google}
  *      'latdeg'   - the latitude in degrees
  *      'londeg'   - the longitude in degrees
  *      'latrad'   - the latitude in radians
  *      'lonrad'   - the longitude in radians
  *      'query'    - the query string that was sent to goggle
  *      'clean_query' - the query as cleaned and standardized by google
  *      'state'    - the state result
  *      'city'     - the city result
  *      'zip'      - the zip result
  *      'street'   - the street result
  *      'country'  - the country result
  *
  * @param string $xml
  * @return array
  */
 public function process($xml)
 {
     // Load the XML, making sure it is all valid utf8
     $xml = @simplexml_load_string(utf8_encode($xml));
     if ($xml === false) {
         // Construct and throw the exception
         $status = GeoCode_Driver_Google::ERROR_BAD_RESPONSE;
         $errMsg = GeoCode_Driver_Google::getErrorMessage($status);
         throw new GeoCode_Exception($errMsg, $status);
     }
     // Get the success status
     $response = $xml->Response;
     $status = $xml->status;
     // If the goecoding was not successfull, error out
     if ($status != GeoCode_Driver_Google::STATUS_SUCCESS) {
         throw new GeoCode_Exception($status);
     }
     # Process the data #
     // Get the location (always returned)
     $lng = $xml->result->geometry->location->lng;
     $lat = $xml->result->geometry->location->lat;
     //list($lon,$lat) = explode(',', (string)$result->geometry->location->coordinates);
     // Initialize the return array
     $data = array('accuracy' => GeoCode_Driver_Google::ACCURACY_UNKNOWN, 'latitude' => (double) $lat, 'longitude' => (double) $lng, 'query' => (string) $xml->result->formatted_address, 'clean_query' => (string) $xml->result->formatted_address, 'state' => '', 'city' => '', 'zip' => '', 'street' => '', 'country' => '');
     // Parse the addressComponent
     $this->parseAddressComponent($xml->result->address_component, $data);
     // Set the accuracy
     if (isset($xml->result->geometry->location_type)) {
         $data['accuracy'] = (string) $xml->result->geometry->location_type;
     }
     // Return our data
     return $data;
 }
Пример #2
0
 /**
  * Parse the XML result
  * The return array returns the following information
  *
  *	  'accuracy' - the Accuracy constant as found in {@link GeoCode_Driver_Google}
  *	  'latdeg'   - the latitude in degrees
  *	  'londeg'   - the longitude in degrees
  *	  'latrad'   - the latitude in radians
  *	  'lonrad'   - the longitude in radians
  *	  'query'    - the query string that was sent to goggle
  *	  'clean_query' - the query as cleaned and standardized by google
  *	  'state'    - the state result
  *	  'city'     - the city result
  *	  'zip'      - the zip result
  *	  'street'   - the street result
  *	  'country'  - the country result
  *
  * @param string $xml
  * @return array
  */
 public function process($xml)
 {
     // Load the XML, making sure it is all valid utf8
     $xml = @simplexml_load_string(utf8_encode($xml));
     if ($xml === false) {
         // Construct and throw the exception
         $status = GeoCode_Driver_Google::ERROR_BAD_RESPONSE;
         $errMsg = GeoCode_Driver_Google::getErrorMessage($status);
         throw new GeoCode_Exception($errMsg, $status);
     }
     // Get the success status
     $response = $xml->Response;
     $status = (int) $response->Status->code;
     // If the goecoding was not successfull, error out
     if ($status != GeoCode_Driver_Google::STATUS_SUCCESS) {
         throw new GeoCode_Exception("GeoCode Query Failed", $status);
     }
     # Process the data #
     // Get the coordinates (always returned)
     $placemark = $response->Placemark;
     list($lon, $lat, $altitude) = explode(',', (string) $placemark->Point->coordinates);
     // Initialize the return array
     $data = array('accuracy' => GeoCode_Driver_Google::ACCURACY_UNKNOWN, 'latitude' => (double) $lat, 'longitude' => (double) $lon, 'query' => (string) $response->name, 'clean_query' => (string) $placemark->address, 'state' => '', 'city' => '', 'zip' => '', 'street' => '', 'country' => '');
     // Parse the placemarker
     $this->parsePlacemark($placemark, $data);
     // Return our data
     return $data;
 }