예제 #1
0
  /**
   * Geocodes the address using the Google Maps XML webservice, which has more information.
   * Unknown values will be set to NULL.
   * @param GMapClient $gmap_client
   * @return integer $accuracy
   * @author Fabrice Bernhard
   */
  public function geocodeXml($gmap_client)
  {
    $raw_data = utf8_encode($gmap_client->getGeocodingInfo($this->getRawAddress(),'xml'));

    $p = xml_parser_create('UTF-8');
    xml_parse_into_struct($p, $raw_data, $vals, $index);
    xml_parser_free($p);

    if ($vals[$index['CODE'][0]]['value'] != 200)
    {

      return false;
    }

    $coordinates = $vals[$index['COORDINATES'][0]]['value'];
    list($this->lng, $this->lat) = explode(',', $coordinates);

    $this->accuracy = $vals[$index['ADDRESSDETAILS'][0]]['attributes']['ACCURACY'];

    // We voluntarily silence errors, the values will still be set to NULL if the array indexes are not defined
    @$this->geocoded_address = $vals[$index['ADDRESS'][0]]['value'];
    @$this->geocoded_street = $vals[$index['THOROUGHFARENAME'][0]]['value'];
    @$this->geocoded_postal_code = $vals[$index['POSTALCODENUMBER'][0]]['value'];
    @$this->geocoded_country = $vals[$index['COUNTRYNAME'][0]]['value'];
    @$this->geocoded_country_code = $vals[$index['COUNTRYNAMECODE'][0]]['value'];

    @$this->geocoded_city = $vals[$index['LOCALITYNAME'][0]]['value'];
    if (empty($this->geocoded_city))
    {
      @$this->geocoded_city = $vals[$index['SUBADMINISTRATIVEAREANAME'][0]]['value'];
    }
    if (empty($this->geocoded_city))
    {
      @$this->geocoded_city = $vals[$index['ADMINISTRATIVEAREANAME'][0]]['value'];
    }

    return $this->accuracy;
  }
예제 #2
0
$t->is($gMapClient->getGoogleJsUrl(false),'http://www.google.com/jsapi?&key=test2','getGoogleJsUrl working');
$t->is($gMapClient->getGoogleJsUrl(true),'http://www.google.com/jsapi?&key=test2&autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22maps%22%2C%22version%22%3A%222%22%7D%5D%7D','getGoogleJsUrl working');
$t->is($gMapClient->getGoogleJsUrl(),'http://www.google.com/jsapi?&key=test2&autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22maps%22%2C%22version%22%3A%222%22%7D%5D%7D','getGoogleJsUrl working');

$t->diag('->setCache / getCache / hasCache');
$t->ok(!$gMapClient->hasCache(),'is not using cache');

require_once(dirname(__FILE__).'/../../lib/GMapClientTestCache.class.php');
$gMapClientTestCache = new GMapClientTestCache();
$gMapClient->setCache($gMapClientTestCache);
$t->ok($gMapClient->hasCache(),'is using cache');

$t->is($gMapClient->getCache(),$gMapClientTestCache,'getCache working');

$t->diag('->getGeocodingInfo');
$t->is($gMapClient->getGeocodingInfo('60 rue de Seine, Paris'),'200,8,48.8537950,2.3369433','Cached geocoding working');
$t->is($gMapClient->getGeocodingInfo('60 rue de Seine, Paris','xml'),'<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
  <name>60 rue de Seine, Paris</name>
  <Status>
    <code>200</code>
    <request>geocode</request>
  </Status>
  <Placemark id="p1">

    <address>60 Rue de Seine, 75006 Paris, France</address>
    <AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>FR</CountryNameCode><CountryName>France</CountryName><AdministrativeArea><AdministrativeAreaName>Île-de-France</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Paris</SubAdministrativeAreaName><Locality><LocalityName>Paris</LocalityName><Thoroughfare><ThoroughfareName>60 Rue de Seine</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>75006</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="48.8569426" south="48.8506474" east="2.3400909" west="2.3337957" />
    </ExtendedData>