diff --git sites/all/modules/location/supported/location.nl.inc sites/all/modules/location/supported/location.nl.inc index f8b8593..09b58b0 100644 --- sites/all/modules/location/supported/location.nl.inc +++ sites/all/modules/location/supported/location.nl.inc @@ -34,6 +34,48 @@ function location_map_link_nl_default_providers() { return array('google'); } +/** + * Returns a lat/lon pair of the approximate center of the given postal code in the given country + * + * @param $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 + * 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 + * + */ +function location_latlon_rough_nl($location = array()) { + if (!isset($location['postal_code'])) { + return NULL; + } + $location['postal_code'] = strtoupper(str_replace(' ', '', $location['postal_code'])); + $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); + } + else { + if ($data = location_latlon_exact($location)) { + $location['source'] = LOCATION_LATLON_GEOCODED_EXACT; + // @@@ How about an accuracy field here? + $location['latitude'] = $data['lat']; + $location['longitude'] = $data['lon']; + // @@@ How about address normalization? + db_query("INSERT INTO {zipcodes} (country, zip, latitude, longitude) VALUES ('%s', '%s', %f, %f)", $location['country'], $location['postal_code'], $location['latitude'], $location['longitude']); + + return array('lat' => $location['latitude'], 'lon' => $location['longitude']); + } + return NULL; + } +} + function location_map_link_nl_google($location = array()) { $query_params = array();