Changeset 12268
- Timestamp:
- 09/14/07 10:39:52 (1 year ago)
- Files:
-
- trunk/midcom/org.routamc.positioning/exec/geocode.php (modified) (3 diffs)
- trunk/midcom/org.routamc.positioning/geocoder/city.php (modified) (1 diff)
- trunk/midcom/org.routamc.positioning/geocoder/geonames.php (modified) (2 diffs)
- trunk/midcom/org.routamc.positioning/geocoder/yahoo.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/org.routamc.positioning/exec/geocode.php
r12255 r12268 9 9 } 10 10 11 if (!isset($_GET['dir'])) 12 { 13 $direction = ''; 14 } 15 else 16 { 17 $direction = 'reverse_'; 18 } 19 11 20 $geocoder = org_routamc_positioning_geocoder::create($service); 12 21 … … 16 25 switch ($key) 17 26 { 27 case 'longitude': 28 case 'latitude': 29 if (! empty($direction)) 30 { 31 $location[$key] = $value; 32 } 18 33 // Accept only XEP-0080 values 19 34 case 'area': … … 34 49 } 35 50 36 $position = $geocoder->geocode($location); 51 $method_name = "{$direction}geocode"; 52 53 $position = $geocoder->$method_name($location); 37 54 if (is_null($position)) 38 55 { trunk/midcom/org.routamc.positioning/geocoder/city.php
r12239 r12268 92 92 return $position; 93 93 } 94 95 /** 96 * Empty default implementation, this won't do anything yet 97 * 98 * @param Array $coordinates Contains latitude and longitude values 99 * @return Array containing geocoded information 100 */ 101 function reverse_geocode($coordinates,$options=array()) 102 { 103 $this->error = 'METHOD_NOT_IMPLEMENTED'; 104 return null; 105 } 94 106 } trunk/midcom/org.routamc.positioning/geocoder/geonames.php
r12255 r12268 26 26 27 27 /** 28 * Empty default implementation, this calls won't do much.29 28 * 30 29 * @param Array $location Parameters to geocode with, conforms to XEP-0080 … … 83 82 return $position; 84 83 } 84 85 /** 86 * 87 * @param Array $coordinates Contains latitude and longitude values 88 * @return Array containing geocoded information 89 */ 90 function reverse_geocode($coordinates,$options=array()) 91 { 92 $parameters = array 93 ( 94 'radius' => null, 95 'maxRows' => null, 96 'style' => 'FULL' 97 ); 98 99 if (! empty($options)) 100 { 101 foreach ($options as $key => $value) 102 { 103 if (isset($parameters[$key])) 104 { 105 $parameters[$key] = $value; 106 } 107 } 108 } 109 110 if ( !isset($coordinates['latitude']) 111 && !isset($coordinates['longitude'])) 112 { 113 $this->error = 'POSITIONING_MISSING_ATTRIBUTES'; 114 return null; 115 } 116 $params = array(); 117 118 $params[] = 'lat=' . urlencode($coordinates['latitude']); 119 $params[] = 'lng=' . urlencode($coordinates['longitude']); 120 121 foreach ($parameters as $key => $value) 122 { 123 if (! is_null($value)) 124 { 125 $params[] = "{$key}=" . urlencode($value); 126 } 127 } 128 129 $http_request = new org_openpsa_httplib(); 130 $response = $http_request->get('http://ws.geonames.org/findNearbyPlaceName?' . implode('&', $params)); 131 $simplexml = simplexml_load_string($response); 132 133 if ( !isset($simplexml->geoname) 134 || count($simplexml->geoname) == 0) 135 { 136 $this->error = 'POSITIONING_DETAILS_NOT_FOUND'; 137 138 if (isset($simplexml->status)) 139 { 140 $constant_name = strtoupper(str_replace(" ", "_",$simplexml->status)); 141 $this->error = $constant_name; 142 } 143 return null; 144 } 145 146 $entry = $simplexml->geoname[0]; 147 $position['latitude' ] = (float) $entry->lat; 148 $position['longitude' ] = (float) $entry->lng; 149 $position['city' ] = (string) $entry->name; 150 $position['region' ] = (string) $entry->adminName2; 151 $position['country' ] = (string) $entry->countryCode; 152 $position['accuracy'] = ORG_ROUTAMC_POSITIONING_ACCURACY_GPS; 153 154 return $position; 155 } 85 156 } trunk/midcom/org.routamc.positioning/geocoder/yahoo.php
r12239 r12268 115 115 return $position; 116 116 } 117 118 /** 119 * Empty default implementation, this won't do anything yet 120 * 121 * @param Array $coordinates Contains latitude and longitude values 122 * @return Array containing geocoded information 123 */ 124 function reverse_geocode($coordinates,$options=array()) 125 { 126 $this->error = 'METHOD_NOT_IMPLEMENTED'; 127 return null; 128 } 117 129 }
