Changeset 7029
- Timestamp:
- 01/12/08 23:23:32 (11 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfGeocoderPlugin/lib/sfGeocoderCache.class.php
r7017 r7029 30 30 { 31 31 return $this->result[$property]; 32 } 33 else 34 { 35 return null; 32 36 } 33 37 plugins/sfGeocoderPlugin/lib/sfGoogleMapsGeocoder.class.php
r7017 r7029 37 37 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 38 38 $response = curl_exec($curl); 39 // convert response to result 39 40 40 $result = array(); 41 41 42 42 $xml = new SimpleXMLElement(utf8_encode ($response)); 43 43 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']; 47 47 48 $country = $address->Country; 48 49 $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 51 51 { 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 } 53 70 } 54 71 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 }63 72 $coord = (String) $xml->Response->Placemark->Point->coordinates; 64 73 list($result['longitude'], $result['latitude']) = explode(',', $coord); 65 74 66 switch($ xml->Response->Placemark->AddressDetails['Accuracy'])75 switch($accuracy) 67 76 { 68 77 case 8: