Development

Changeset 12104

You must first sign up to be able to contribute.

Changeset 12104

Show
Ignore:
Timestamp:
10/09/08 10:55:36 (6 years ago)
Author:
laurentb
Message:

GeocodeXML: Fixed behavior on incomplete responses; support for street name, country name and postal code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfEasyGMapPlugin/trunk/lib/GMapGeocodedAddress.class.php

    r12072 r12104  
    1616  protected $geocoded_country      = null; 
    1717  protected $geocoded_address      = null; 
     18  protected $geocoded_street       = null; 
     19  protected $geocoded_postal_code  = null; 
    1820 
    1921  /** 
     
    2931 
    3032  /** 
    31    * Geocodes the address using Google Maps CSV webservice 
     33   * Geocodes the address using the Google Maps CSV webservice 
    3234   * 
    3335   * @param String $api_key 
     
    5355 
    5456  /** 
    55    * Geocodes the address using Google Mapx XML webservice, which has more information 
    56    * 
     57   * Geocodes the address using the Google Maps XML webservice, which has more information. 
     58   * Unknown values will be set to NULL. 
    5759   * @param String $api_key 
    5860   * @return Integer $accuracy 
     
    7577 
    7678    $coordinates = $vals[$index['COORDINATES'][0]]['value']; 
    77     $coordArray = explode(',',$coordinates); 
    78     $this->lat = $coordArray[1]; 
    79     $this->lng = $coordArray[0]; 
     79    list($this->lng, $this->lat) = explode(',', $coordinates); 
     80 
    8081    $this->accuracy = $vals[$index['ADDRESSDETAILS'][0]]['attributes']['ACCURACY']; 
    81     $this->geocoded_address = $vals[$index['ADDRESS'][0]]['value']; 
    82     $this->geocoded_country_code = $vals[$index['COUNTRYNAMECODE'][0]]['value']; 
    83     $this->geocoded_city = $vals[$index['LOCALITYNAME'][0]]['value']; 
    84     if ($this->geocoded_city == '') 
     82 
     83    // We voluntarily silence errors, the values will still be set to NULL if the array indexes are not defined 
     84    @$this->geocoded_address = $vals[$index['ADDRESS'][0]]['value']; 
     85    @$this->geocoded_street = $vals[$index['THOROUGHFARENAME'][0]]['value']; 
     86    @$this->geocoded_postal_code = $vals[$index['POSTALCODENUMBER'][0]]['value']; 
     87    @$this->geocoded_country = $vals[$index['COUNTRYNAME'][0]]['value']; 
     88    @$this->geocoded_country_code = $vals[$index['COUNTRYNAMECODE'][0]]['value']; 
     89 
     90    @$this->geocoded_city = $vals[$index['LOCALITYNAME'][0]]['value']; 
     91    if (empty($this->geocoded_city)) 
    8592    { 
    86       $this->geocoded_city = $vals[$index['SUBADMINISTRATIVEAREANAME'][0]]['value']; 
     93      @$this->geocoded_city = $vals[$index['SUBADMINISTRATIVEAREANAME'][0]]['value']; 
    8794    } 
    88     if ($this->geocoded_city == ''
     95    if (empty($this->geocoded_city)
    8996    { 
    90       $this->geocoded_city = $vals[$index['ADMINISTRATIVEAREANAME'][0]]['value']; 
     97      @$this->geocoded_city = $vals[$index['ADMINISTRATIVEAREANAME'][0]]['value']; 
    9198    } 
    9299 
     
    96103 
    97104  /** 
    98    * Returns Latitude 
     105   * Returns the latitude 
    99106   * @return Decimal $latitude 
    100107   */ 
     
    104111    return $this->lat; 
    105112  } 
     113 
    106114  /** 
    107    * Returns longitude 
     115   * Returns the longitude 
    108116   * @return Decimal $longitude 
    109117   */ 
     
    113121    return $this->lng; 
    114122  } 
     123 
    115124  /** 
    116    * Returns Geocoding accuracy 
     125   * Returns the Geocoding accuracy 
    117126   * @return Integer $accuracy 
    118127   */ 
     
    122131    return $this->accuracy; 
    123132  } 
     133 
    124134  /** 
    125    * Returns address as normalized by the Google Maps web service 
     135   * Returns the address normalized by the Google Maps web service 
    126136   * @return String $geocoded_address 
    127137   */ 
     
    131141    return $this->geocoded_address; 
    132142  } 
     143 
    133144  /** 
    134    * Returns city as normalized by the Google Maps web service 
     145   * Returns the city normalized by the Google Maps web service 
    135146   * @return String $geocoded_city 
    136147   */ 
     
    140151    return $this->geocoded_city; 
    141152  } 
     153 
    142154  /** 
    143    * Returns country code as normalized by the Google Maps web service 
     155   * Returns the country code normalized by the Google Maps web service 
    144156   * @return String $geocoded_country_code 
    145157   */ 
     
    150162  } 
    151163 
     164  /** 
     165   * Returns the country normalized by the Google Maps web service 
     166   * @return String $geocoded_country 
     167   */ 
     168  public function getGeocodedCountry() 
     169  { 
     170 
     171    return $this->geocoded_country; 
     172  } 
     173 
     174  /** 
     175   * Returns the postal code normalized by the Google Maps web service 
     176   * @return String $geocoded_postal_code 
     177   */ 
     178  public function getGeocodedPostalCode() 
     179  { 
     180 
     181    return $this->geocoded_postal_code; 
     182  } 
     183 
     184  /** 
     185   * Returns the street name normalized by the Google Maps web service 
     186   * @return String $geocoded_country_code 
     187   */ 
     188  public function getGeocodedStreet() 
     189  { 
     190 
     191    return $this->geocoded_street; 
     192  } 
     193 
    152194}