function _location_latlon_exact_nz_geocoder in Location 7.3
Calls up a web-service to retrieve a lat/lon pair for a full, correct NZ location.
Parameters
array $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
array 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.nz.inc, line 202 - New Zealand.
Code
function _location_latlon_exact_nz_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 {
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;
}