Development

Changeset 7029

You must first sign up to be able to contribute.

Changeset 7029

Show
Ignore:
Timestamp:
01/12/08 23:23:32 (11 months ago)
Author:
davedash
Message:

sfGeocoderPlugin: Handle country only searches much better.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfGeocoderPlugin/lib/sfGeocoderCache.class.php

    r7017 r7029  
    3030      { 
    3131        return $this->result[$property]; 
     32      } 
     33      else 
     34      { 
     35        return null; 
    3236      } 
    3337 
  • plugins/sfGeocoderPlugin/lib/sfGoogleMapsGeocoder.class.php

    r7017 r7029  
    3737      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    3838      $response = curl_exec($curl); 
    39       // convert response to result 
     39 
    4040      $result = array(); 
    4141       
    4242      $xml                 = new SimpleXMLElement(utf8_encode ($response)); 
    4343       
    44       $country = $xml->Response->Placemark->AddressDetails->Country; 
    45       $state   = $country->AdministrativeArea
    46       $city    = $state->Locality
     44      // get accuracy first! 
     45      $address = $xml->Response->Placemark->AddressDetails
     46      $accuracy = $address['Accuracy']
    4747 
     48      $country = $address->Country; 
    4849      $result['country']   = (String) $country->CountryNameCode; 
    49       $result['state']     = (String) $state->AdministrativeAreaName; 
    50       if ($city->LocalityName) 
     50      if ($accuracy > 1) // we're accurate to country level only 
    5151      { 
    52         $result['city']      = (String) $city->LocalityName; 
     52       
     53        $state   = $country->AdministrativeArea; 
     54        $city    = $state->Locality; 
     55 
     56        $result['state']     = (String) $state->AdministrativeAreaName; 
     57        if ($city->LocalityName) 
     58        { 
     59          $result['city']      = (String) $city->LocalityName; 
     60        } 
     61       
     62        if ($city->Thoroughfare) 
     63        { 
     64          $result['address']   = (String) $city->Thoroughfare->ThoroughfareName; 
     65        } 
     66        if ($city->PostalCode) 
     67        { 
     68          $result['zip'] = (String) $city->PostalCode->PostalCodeNumber; 
     69        } 
    5370      } 
    5471       
    55       if ($city->Thoroughfare) 
    56       { 
    57         $result['address']   = (String) $city->Thoroughfare->ThoroughfareName; 
    58       } 
    59       if ($city->PostalCode) 
    60       { 
    61         $result['zip'] = (String) $city->PostalCode->PostalCodeNumber; 
    62       } 
    6372      $coord               = (String) $xml->Response->Placemark->Point->coordinates; 
    6473      list($result['longitude'], $result['latitude']) = explode(',', $coord); 
    6574       
    66       switch($xml->Response->Placemark->AddressDetails['Accuracy']
     75      switch($accuracy
    6776      { 
    6877        case 8: