Exemplo n.º 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;
 }