Needs work
Project:
Location
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
6 Mar 2011 at 07:33 UTC
Updated:
12 Mar 2013 at 15:53 UTC
A few changes for Drupal 7 to accommodate the database provided in the above link. The changes support lat / lon for users and proximity search.
location.ca.inc
<?php
function location_latlon_rough_ca($location = array()) {
if (!isset($location['postal_code'])) {
return NULL;
}
$postal_code = $location['postal_code'];
while (strlen($postal_code) >= 3) {
$row = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = :country AND zip LIKE :zip", array(':country' => $location['country'], ':zip' => db_like($postal_code) . '%'))->fetchObject();
if ($row) {
return array('lat' => $row->latitude, 'lon' => $row->longitude);
}
$postal_code = trim(substr($postal_code, 0, -1));
}
return NULL;
}
function location_get_postalcode_data_ca($location = array()) {
$postal_code = $location['postal_code'];
// Now we pad the thing and query.
while (strlen($postal_code) >= 3) {
$row = db_query("SELECT * FROM {zipcodes} where country = :country AND zip LIKE :zip", array(':country' => $location['country'], ':zip' => db_like($postal_code) . '%'))->fetchObject();
if ($row) {
return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country);
}
$postal_code = trim(substr($postal_code, 0, -1));
}
return NULL;
}
?>
| Comment | File | Size | Author |
|---|---|---|---|
| location.ca_.inc_.patch | 2.05 KB | nathaniel |
Comments
Comment #1
shiraz dindarNathaniel,
D7 Canadian postal code proximity searches are working for me already, after having added the DB from #20 as in your link, without patching. That is to say, if a user provides only their postal code during registration, location will correctly geocode their lat/lon, and then proximity searches work fine.
Is this because you are addressing something different in your patch, or is it because your patch has already been rolled in dev?
Thanks,
Shiraz
Comment #2
nathaniel commentedI believe the patch addresses an issue if someone enters a partial postal code or a postal code that is not in the database provided in the link. So it will select the most accurate postal code if not found.
Quoted from this comment: http://drupal.org/node/255995#comment-2620136
Comment #3
colan...which is discussed over at #255995: Canadian postal codes for MySQL zipcodes table.
Comment #4
podarok#1931088: [META] Fixing tests tests were broken, so triggering to active
Comment #5
podarokbot