function _location_latlon_postalcode_no in Location 7.4
Same name and namespace in other branches
- 5.3 supported/location.no.inc \_location_latlon_postalcode_no()
- 6.3 supported/location.no.inc \_location_latlon_postalcode_no()
- 7.5 supported/location.no.inc \_location_latlon_postalcode_no()
- 7.3 supported/location.no.inc \_location_latlon_postalcode_no()
Returns a lat/lon pair of the approximate center of the given postal code in the given country
Parameters
$location: An associative array $location where only postal code and country are necessary, but can have the keys: 'street' => the street portion of the location 'supplemental' => additional street portion of the location 'province' => the province, state, or territory 'country' => lower-cased two-letter ISO code (REQUIRED) 'postal_code' => the international postal code for this location (REQUIRED)
Return value
An associative array where 'lat' => approximate latitude of the center of the postal code's area 'lon' => approximate longitude of the center of the postal code's area 'city' => the city 'province' => the province, state, or territory 'country' => lower-cased two-letter ISO code
File
- supported/
location.no.inc, line 62
Code
function _location_latlon_postalcode_no($location = array()) {
// Now we pad the thing and query.
$result = db_query("SELECT * FROM {zipcodes} where country = :country AND zip = :zip", array(
':country' => $location['country'],
':zip' => $location['postal_code'],
));
if (($row = $result
->fetchObject()) !== FALSE) {
return array(
'lat' => $row->latitude,
'lon' => $row->longitude,
'city' => $row->city,
'province' => $row->state,
'country' => $row->country,
);
}
else {
return NULL;
}
}