Example #1
0
 /**
  * Request the elevation info using Google Maps' API XML
  *
  * @param  EGMapClient $gmap_client
  * @param $forceEncode whether to encode the lat/lng points
  * @return array of EGMapElevationInfoResult if successful
  * @author Antonio Ramirez
  */
 public function elevationRequestXml($gmap_client, $forceEncode = true)
 {
     if (empty($this->coords)) {
         return false;
     }
     $this->locations = array();
     $coords = array();
     /* At least 3 coords otherwise is not point */
     if ($forceEncode && count($this->coords) > 2) {
         $coords = $this->prepareEncodedCoords($this->coords);
     } else {
         $coords = implode('|', $this->coords);
     }
     $raw_data = $gmap_client->getElevationInfo($coords, 'xml');
     $xml = simplexml_load_string($raw_data);
     if ('OK' != $xml->status) {
         return false;
     }
     foreach ($xml->result as $component) {
         $info = new EGMapElevationInfoResult();
         $info->lat = $component->location->lat;
         $info->lng = $component->location->lng;
         $info->elevation = $component->elevation;
         $info->resolution = $component->resolution;
         $this->locations[] = $info;
     }
     return $this->locations;
 }
Example #2
0
 /**
  * backwards compatibility
  * @param string[] $api_keys
  * @return string
  * @author fabriceb
  * @since Jun 17, 2009 fabriceb
  * @since 2010-12-22 modified for Yii Antonio Ramirez
  */
 public static function guessAPIKey($api_keys = null)
 {
     return EGMapClient::guessAPIKey($api_keys);
 }
 /**
  * Geocodes the address using the Google Maps XML webservice, which has more information.
  * Unknown values will be set to NULL.
  * @todo Change to SimpleXML
  * @param EGMapClient $gmap_client
  * @return integer $accuracy
  * @author Fabrice Bernhard
  * @since 2010-12-22 modified by utf8_encode removed Antonio Ramirez
  * @since 2011-04-21 Matt Cheale Updated to parse API V3 JSON response.
  */
 public function geocodeXml($gmap_client)
 {
     $raw_data = $gmap_client->getGeocodingInfo($this->getRawAddress(), 'xml');
     $xml = simplexml_load_string($raw_data);
     if ('OK' != $xml->status) {
         return false;
     }
     foreach ($xml->result->address_component as $component) {
         $longName = (string) $component->long_name;
         $shortName = (string) $component->short_name;
         foreach ($component->type as $type) {
             switch ($type) {
                 case 'street_address':
                 case 'route':
                     $this->geocoded_street = $longName;
                     break;
                 case 'country':
                     $this->geocoded_country = $longName;
                     $this->geocoded_country_code = $shortName;
                     break;
                 case 'locality':
                     $this->geocoded_city = $shortName;
                     break;
                 case 'postal_code':
                     $this->geocoded_postal_code = $longName;
                     break;
                 default:
                     // Do nothing
             }
         }
     }
     $this->lat = (double) $xml->result->geometry->location->lat;
     $this->lng = (double) $xml->result->geometry->location->lng;
     $this->accuracy = (string) $xml->result->geometry->location_type;
     return $this->accuracy;
 }
Example #4
0
 /**
  * Geocodes the address using the Google Maps XML webservice, which has more information.
  * Unknown values will be set to NULL.
  * @todo Change to SimpleXML
  * @param EGMapClient $gmap_client
  * @return integer $accuracy
  * @author Fabrice Bernhard
  * @since 2010-12-22 modified by utf8_encode removed Antonio Ramirez
  */
 public function geocodeXml($gmap_client)
 {
     $raw_data = $gmap_client->getGeocodingInfo($this->getRawAddress(), 'xml');
     $p = xml_parser_create('UTF-8');
     xml_parse_into_struct($p, $raw_data, $vals, $index);
     xml_parser_free($p);
     if ($vals[$index['CODE'][0]]['value'] != 200) {
         return false;
     }
     $coordinates = $vals[$index['COORDINATES'][0]]['value'];
     list($this->lng, $this->lat) = explode(',', $coordinates);
     $this->accuracy = $vals[$index['ADDRESSDETAILS'][0]]['attributes']['ACCURACY'];
     // We voluntarily silence errors, the values will still be set to NULL if the array indexes are not defined
     // @author Fabrice Bernard
     @($this->geocoded_address = $vals[$index['ADDRESS'][0]]['value']);
     @($this->geocoded_street = $vals[$index['THOROUGHFARENAME'][0]]['value']);
     @($this->geocoded_postal_code = $vals[$index['POSTALCODENUMBER'][0]]['value']);
     @($this->geocoded_country = $vals[$index['COUNTRYNAME'][0]]['value']);
     @($this->geocoded_country_code = $vals[$index['COUNTRYNAMECODE'][0]]['value']);
     @($this->geocoded_city = $vals[$index['LOCALITYNAME'][0]]['value']);
     if (empty($this->geocoded_city)) {
         @($this->geocoded_city = $vals[$index['SUBADMINISTRATIVEAREANAME'][0]]['value']);
     }
     if (empty($this->geocoded_city)) {
         @($this->geocoded_city = $vals[$index['ADMINISTRATIVEAREANAME'][0]]['value']);
     }
     return $this->accuracy;
 }