eXorithm – Execute Algorithm: View / Run Algorithm address_elevation

Logo Beta

function address_elevation ($address
{
  // get the lat/long for this address
  $data = file_get_contents"http://maps.google.com/maps/geo?output=csv&q="urlencode$address));
  $arr = explode","$data);
  if (count$arr)>=4) {
    if ($arr[0]==200) {
      // get the elevation for this lat/long
      $data = file_get_contents"http://maps.googleapis.com/maps/api/elevation/xml?sensor=false&locations="$arr[2].','$arr[3]);
      $obj = simplexml_load_string$data);
      if ($obj instanceof SimpleXMLElement) {
        $obj = (array) $obj
        $obj = $obj'result'];
        if ($obj instanceof SimpleXMLElement) {
          $obj = (array) $obj
          return $obj'elevation'];
        } else {
          throw new Exception'Elevation lookup failed');
        }
      } else {
        throw new Exception'Elevation lookup failed');
      }
    } else {
      throw new Exception'Address lookup failed');
    }
  } else {
    throw new Exception'Address lookup failed');
  }