You are here

function _location_latlon_exact_au_geocoder in Location 7.4

Same name and namespace in other branches
  1. 5.3 supported/location.au.inc \_location_latlon_exact_au_geocoder()
  2. 6.3 supported/location.au.inc \_location_latlon_exact_au_geocoder()
  3. 7.5 supported/location.au.inc \_location_latlon_exact_au_geocoder()
  4. 7.3 supported/location.au.inc \_location_latlon_exact_au_geocoder()

Calls up a web-service to retrieve a lat/lon pair for a full, correct U.S. location.

Parameters

$location: An associative array that represents an location where 'street' => is the street location 'supplemental' => any supplemental portion to the street location 'city' => city name 'province' => state, province, or territorial abbreviation 'postal_code' => postal code

Return value

An associative array where 'lat' => Is a float value in latitude 'lon' => Is a float value in longitude If the location supplied does not provide enough information, NULL is returned. "Enough information" means that there is either (a valid 'street' AND valid 'postal_code') OR (valid 'street' AND valid 'city' AND valid 'province')

File

supported/location.au.inc, line 108

Code

function _location_latlon_exact_au_geocoder($location = array()) {
  $location_string = '';
  if (isset($location['street']) && trim($location['street']) != '') {
    if (isset($location['postal_code'])) {
      $location_string = $location['street'] . ' ' . $location['postal_code'];
    }
    elseif (isset($location['city']) && isset($location['province']) && trim($location['city']) != '' && trim($location['province'])) {
      $location_string = $location['street'] . ', ' . $location['city'] . ', ' . $location['province'];
    }
    else {

      // else geocoder.us won't do bidness with you!
      return NULL;
    }
  }
  else {
    return NULL;
  }
  $result = xmlrpc('http://rpc.geocoder.us/service/xmlrpc', 'geocode', $location_string);
  if (is_array($result) && is_array($result[0]) && isset($result[0]['lat']) && is_numeric($result[0]['lat']) && isset($result[0]['long']) && is_numeric($result[0]['long'])) {
    return array(
      'lat' => $result[0]['lat'],
      'lon' => $result[0]['long'],
    );
  }
  return NULL;
}