From 72a4c6a8987a0a1d34e3d76f8c9673f3e3ad3ebf Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 13 May 2011 10:13:52 +0200 Subject: [PATCH] Stores more geocoding information in addresses. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/address.php | 17 ++++++++++++----- classes/gmapsgeocoder.php | 2 ++ templates/geoloc/form.address.tpl | 2 ++ upgrade/1.1.2/01_geocoding.sql | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/classes/address.php b/classes/address.php index 65ae7a2..7bea442 100644 --- a/classes/address.php +++ b/classes/address.php @@ -311,6 +311,8 @@ class Address public $partial_match = false; public $componentsIds = ''; public $request = false; + public $geocoding_date = null; + public $geocoding_calls = 0; // Database's field required for both 'home' and 'job' addresses. public $pub = 'ax'; @@ -614,6 +616,8 @@ class Address 'location_type' => $this->location_type, 'partial_match' => $this->partial_match, 'componentsIds' => $this->componentsIds, + 'geocoding_date' => $this->geocoding_date, + 'geocoding_calls' => $this->geocoding_calls, 'request' => $this->request ); @@ -682,12 +686,13 @@ class Address if (!$this->isEmpty()) { XDB::execute('INSERT IGNORE INTO profile_addresses (pid, jobid, groupid, type, id, flags, text, postalText, pub, comment, types, formatted_address, location_type, partial_match, latitude, longitude, - southwest_latitude, southwest_longitude, northeast_latitude, northeast_longitude) + southwest_latitude, southwest_longitude, northeast_latitude, northeast_longitude, + geocoding_date, geocoding_calls) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, - {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, NOW(), {?})', $this->pid, $this->jobid, $this->groupid, $this->type, $this->id, $this->flags, $this->text, $this->postalText, $this->pub, $this->comment, $this->types, $this->formatted_address, $this->location_type, $this->partial_match, $this->latitude, $this->longitude, - $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude); + $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude, $this->geocoding_calls); if ($this->componentsIds) { foreach (explode(',', $this->componentsIds) as $component_id) { @@ -721,12 +726,13 @@ class Address XDB::execute('UPDATE profile_addresses SET text = {?}, postalText = {?}, types = {?}, formatted_address = {?}, location_type = {?}, partial_match = {?}, latitude = {?}, longitude = {?}, - southwest_latitude = {?}, southwest_longitude = {?}, northeast_latitude = {?}, northeast_longitude = {?} + southwest_latitude = {?}, southwest_longitude = {?}, northeast_latitude = {?}, northeast_longitude = {?}, + geocoding_date = {?}, geocoding_calls = NOW() WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', $this->text, $this->postalText, $this->types, $this->formatted_address, $this->location_type, $this->partial_match, $this->latitude, $this->longitude, $this->southwest_latitude, $this->southwest_longitude, $this->northeast_latitude, $this->northeast_longitude, - $this->pid, $this->jobid, $this->groupid, $this->type, $id); + $this->pid, $this->jobid, $this->groupid, $this->type, $id, $this->geocoding_calls); XDB::execute('DELETE FROM profile_addresses_components WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', @@ -901,6 +907,7 @@ class AddressIterator implements PlIterator $sql = 'SELECT pa.pid, pa.jobid, pa.groupid, pa.type, pa.id, pa.flags, pa.text, pa.postalText, pa.pub, pa.comment, pa.types, pa.formatted_address, pa.location_type, pa.partial_match, pa.latitude, pa.longitude, pa.southwest_latitude, pa.southwest_longitude, pa.northeast_latitude, pa.northeast_longitude, + pa.geocoding_date, pa.geocoding_calls, GROUP_CONCAT(DISTINCT pc.component_id SEPARATOR \',\') AS componentsIds, pace1.long_name AS postalCode, pace2.long_name AS locality, pace3.long_name AS administrativeArea, pace4.long_name AS country FROM profile_addresses AS pa diff --git a/classes/gmapsgeocoder.php b/classes/gmapsgeocoder.php index 9378c1b..5321c72 100644 --- a/classes/gmapsgeocoder.php +++ b/classes/gmapsgeocoder.php @@ -38,6 +38,7 @@ class GMapsGeocoder extends Geocoder { } // Try to geocode the full address. + $address->geocoding_calls = 1; if (($geocodedData = $this->getPlacemarkForAddress($textAddress, $defaultLanguage))) { $this->getUpdatedAddress($address, $geocodedData, null, $forceLanguage); return; @@ -52,6 +53,7 @@ class GMapsGeocoder extends Geocoder { for ($i = max(1, $linesCount - self::MAX_GMAPS_RPC_CALLS + 1); $i < $linesCount; ++$i) { $extraLines = implode("\n", array_slice($addressLines, 0, $i)); $toGeocode = implode("\n", array_slice($addressLines, $i)); + ++$address->geocoding_calls; if (($geocodedData = $this->getPlacemarkForAddress($toGeocode, $defaultLanguage))) { $this->getUpdatedAddress($address, $geocodedData, $extraLines, $forceLanguage); return; diff --git a/templates/geoloc/form.address.tpl b/templates/geoloc/form.address.tpl index e419512..33c32a5 100644 --- a/templates/geoloc/form.address.tpl +++ b/templates/geoloc/form.address.tpl @@ -41,6 +41,8 @@ + + {if t($validation)}
diff --git a/upgrade/1.1.2/01_geocoding.sql b/upgrade/1.1.2/01_geocoding.sql index b89083d..051ff08 100644 --- a/upgrade/1.1.2/01_geocoding.sql +++ b/upgrade/1.1.2/01_geocoding.sql @@ -48,6 +48,8 @@ ALTER TABLE profile_addresses ADD COLUMN northeast_latitude FLOAT(10, 7) DEFAULT ALTER TABLE profile_addresses ADD COLUMN northeast_longitude FLOAT(10, 7) DEFAULT NULL AFTER northeast_latitude; ALTER TABLE profile_addresses ADD COLUMN location_type ENUM('ROOFTOP', 'RANGE_INTERPOLATED', 'GEOMETRIC_CENTER', 'APPROXIMATE') DEFAULT NULL AFTER northeast_longitude; ALTER TABLE profile_addresses ADD COLUMN partial_match BOOLEAN NOT NULL DEFAULT false AFTER location_type; +ALTER TABLE profile_addresses ADD COLUMN geocoding_date DATE DEFAULT NULL; +ALTER TABLE profile_addresses ADD COLUMN geocoding_calls TINYINT NOT NULL DEFAULT 0; UPDATE profile_addresses SET latitude = NULL, longitude = NULL; -- 2.1.4