Changeset 12268

Show
Ignore:
Timestamp:
09/14/07 10:39:52 (1 year ago)
Author:
w_i
Message:

Added reverse geocoding possibility

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/org.routamc.positioning/exec/geocode.php

    r12255 r12268  
    99} 
    1010 
     11if (!isset($_GET['dir'])) 
     12{ 
     13    $direction = ''; 
     14} 
     15else 
     16{ 
     17    $direction = 'reverse_'; 
     18} 
     19 
    1120$geocoder = org_routamc_positioning_geocoder::create($service); 
    1221 
     
    1625    switch ($key) 
    1726    { 
     27        case 'longitude': 
     28        case 'latitude': 
     29            if (! empty($direction)) 
     30            { 
     31                $location[$key] = $value; 
     32            } 
    1833        // Accept only XEP-0080 values 
    1934        case 'area': 
     
    3449} 
    3550 
    36 $position = $geocoder->geocode($location); 
     51$method_name = "{$direction}geocode"; 
     52 
     53$position = $geocoder->$method_name($location); 
    3754if (is_null($position)) 
    3855{ 
  • trunk/midcom/org.routamc.positioning/geocoder/city.php

    r12239 r12268  
    9292        return $position; 
    9393    } 
     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    } 
    94106} 
  • trunk/midcom/org.routamc.positioning/geocoder/geonames.php

    r12255 r12268  
    2626 
    2727    /** 
    28      * Empty default implementation, this calls won't do much. 
    2928     * 
    3029     * @param Array $location Parameters to geocode with, conforms to XEP-0080 
     
    8382        return $position; 
    8483    } 
     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    } 
    85156} 
  • trunk/midcom/org.routamc.positioning/geocoder/yahoo.php

    r12239 r12268  
    115115        return $position; 
    116116    } 
     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    } 
    117129}