| 1 |
<?php |
<?php |
| 2 |
// $Id: location.us.inc,v 1.23 2008/08/21 16:18:05 bdragon Exp $ |
// $Id: location.us.inc,v 1.24 2009/02/04 23:21:56 bdragon Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Returns a lat/lon pair of the approximate center of the given postal code in the given country |
* Returns a lat/lon pair of the approximate center of the given postal code in the given country |
| 23 |
return NULL; |
return NULL; |
| 24 |
} |
} |
| 25 |
|
|
| 26 |
$result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], substr(str_pad($location['postal_code'], 5, '0', STR_PAD_LEFT), 0, 5)); |
$result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = :country AND zip = :zip", array(':country' => $location['country'], ':zip' => substr(str_pad($location['postal_code'], 5, '0', STR_PAD_LEFT), 0, 5))); |
| 27 |
|
if (($row = $result->fetchObject()) !== FALSE) { |
|
if ($row = db_fetch_object($result)) { |
|
| 28 |
return array('lat' => $row->latitude, 'lon' => $row->longitude); |
return array('lat' => $row->latitude, 'lon' => $row->longitude); |
| 29 |
} |
} |
| 30 |
else { |
else { |
| 57 |
} |
} |
| 58 |
|
|
| 59 |
// Now we pad the thing and query. |
// Now we pad the thing and query. |
| 60 |
$res = db_query("SELECT * FROM {zipcodes} where country = '%s' AND zip = '%s'", $location['country'], str_pad($location['postal_code'], 5, "0", STR_PAD_LEFT)); |
$res = db_query("SELECT * FROM {zipcodes} where country = :country AND zip = :zip", array(':country' => $location['country'], ':zip' => str_pad($location['postal_code'], 5, "0", STR_PAD_LEFT))); |
| 61 |
if ($row = db_fetch_object($res)) { |
if (($row = $result->fetchObject()) !== FALSE) { |
| 62 |
return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country); |
return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country); |
| 63 |
} |
} |
| 64 |
else { |
else { |