function location_latlon_rough_default in Location 5.3
Same name and namespace in other branches
- 6.3 location.inc \location_latlon_rough_default()
- 7.5 location.inc \location_latlon_rough_default()
- 7.3 location.inc \location_latlon_rough_default()
- 7.4 location.inc \location_latlon_rough_default()
Returns a lat/lon pair of the approximate center of the given postal code in the given country This function is a default implementation, in case the country support doesn't implement a proper function for this.
Parameters
$location: An associative array $location where '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
1 call to location_latlon_rough_default()
- location_latlon_rough in ./
location.inc - Takes an location and returns a "rough" latitude/longitude pair based on the postal code data available for the given country.
File
- ./
location.inc, line 303
Code
function location_latlon_rough_default($location = array()) {
if (!isset($location['country']) || !isset($location['postal_code'])) {
return NULL;
}
$result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], $location['postal_code']);
if ($row = db_fetch_object($result)) {
return array(
'lat' => $row->latitude,
'lon' => $row->longitude,
);
}
elseif (($newlatlong = location_latlon_exact($location)) != NULL) {
// try a one-time external geocoding
if ($newlatlong['lat']) {
// and store results in zipcodes table for next lookups being internally handled
// (yeah this is missing city/state info a.t.m., but is way better than nothing!)
$result = db_query("INSERT INTO {zipcodes} (latitude, longitude, country, zip) values ('%s', '%s', '%s', '%s')", $newlatlong['lat'], $newlatlong['lon'], $location['country'], $location['postal_code']);
}
return $newlatlong;
}
else {
return NULL;
}
}