From 2eccb0e69dd4e443ec534fb9baa374b76ee7e57f Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Thu, 7 Apr 2011 15:57:57 +0000 Subject: [PATCH] return actual centroid lat,lon of reverse geocoding result --- lib/template/address-json.php | 2 ++ lib/template/address-jsonv2.php | 2 ++ lib/template/address-xml.php | 2 ++ website/reverse.php | 9 ++++++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/template/address-json.php b/lib/template/address-json.php index 4ae41116..29e6e901 100644 --- a/lib/template/address-json.php +++ b/lib/template/address-json.php @@ -21,6 +21,8 @@ $aFilteredPlaces['osm_type'] = $sOSMType; $aFilteredPlaces['osm_id'] = $aPlace['osm_id']; } + if (isset($aPlace['lat'])) $aFilteredPlaces['lat'] = $aPlace['lat']; + if (isset($aPlace['lon'])) $aFilteredPlaces['lon'] = $aPlace['lon']; $aFilteredPlaces['display_name'] = $aPlace['langaddress']; $aFilteredPlaces['address'] = $aAddress; } diff --git a/lib/template/address-jsonv2.php b/lib/template/address-jsonv2.php index b6fa58fe..f9592d8b 100644 --- a/lib/template/address-jsonv2.php +++ b/lib/template/address-jsonv2.php @@ -21,6 +21,8 @@ $aFilteredPlaces['osm_type'] = $sOSMType; $aFilteredPlaces['osm_id'] = $aPlace['osm_id']; } + if (isset($aPlace['lat'])) $aFilteredPlaces['lat'] = $aPlace['lat']; + if (isset($aPlace['lon'])) $aFilteredPlaces['lon'] = $aPlace['lon']; $aFilteredPlaces['category'] = $aPlace['class']; $aFilteredPlaces['type'] = $aPlace['type']; $aFilteredPlaces['addresstype'] = strtolower($aPlace['addresstype']); diff --git a/lib/template/address-xml.php b/lib/template/address-xml.php index dc9f0548..d6061e3d 100644 --- a/lib/template/address-xml.php +++ b/lib/template/address-xml.php @@ -25,6 +25,8 @@ if ($aPlace['place_id']) echo ' place_id="'.$aPlace['place_id'].'"'; if ($aPlace['osm_type'] && $aPlace['osm_id']) echo ' osm_type="'.($aPlace['osm_type']=='N'?'node':($aPlace['osm_type']=='W'?'way':'relation')).'"'.' osm_id="'.$aPlace['osm_id'].'"'; if ($aPlace['ref']) echo ' ref="'.htmlspecialchars($aPlace['ref']).'"'; + if (isset($aPlace['lat'])) echo ' lat="'.htmlspecialchars($aPlace['lat']).'"'; + if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"'; echo ">".htmlspecialchars($aPlace['langaddress']).""; echo ""; diff --git a/website/reverse.php b/website/reverse.php index b0205d22..f569ffac 100755 --- a/website/reverse.php +++ b/website/reverse.php @@ -113,7 +113,8 @@ // The point we found might be too small - use the address to find what it is a child of if ($iPlaceID) { - $sSQL = "select address_place_id from place_addressline where cached_rank_address <= $iMaxRank and place_id = $iPlaceID order by cached_rank_address desc,isaddress desc,distance desc"; + $sSQL = "select address_place_id from place_addressline where cached_rank_address <= $iMaxRank and place_id = $iPlaceID order by cached_rank_address desc,isaddress desc,distance desc limit 1"; +//var_dump($sSQL); $iPlaceID = $oDB->getOne($sSQL); if (PEAR::IsError($iPlaceID)) { @@ -124,6 +125,7 @@ if ($iPlaceID && $aPlace['place_id'] && $iMaxRank < 28) { $sSQL = "select address_place_id from place_addressline where cached_rank_address <= $iMaxRank and place_id = ".$aPlace['place_id']." order by cached_rank_address desc,isaddress desc,distance desc"; +//var_dump($sSQL); $iPlaceID = $oDB->getOne($sSQL); if (PEAR::IsError($iPlaceID)) { @@ -143,15 +145,16 @@ $sSQL = "select placex.*,"; $sSQL .= " get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,"; $sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL) as placename,"; - $sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref"; + $sSQL .= " get_name_by_language(name, ARRAY['ref']) as ref,"; + $sSQL .= " st_y(st_centroid(geometry)) as lat, st_x(st_centroid(geometry)) as lon"; $sSQL .= " from placex where place_id = $iPlaceID "; +//var_dump($sSQL); $aPlace = $oDB->getRow($sSQL); if ($bShowAddressDetails) { $aAddress = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPlace['country_code']); } - $aClassType = getClassTypes(); $sAddressType = ''; if (isset($aClassType[$aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level']])) -- 2.39.5