Пример #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
  /**
   * backwards compatibility
   * @param string[] $api_keys
   * @return string
   * @author fabriceb
   * @since Jun 17, 2009 fabriceb
   */
  public static function guessAPIKey($api_keys = null)
  {

    return GMapClient::guessAPIKey($api_keys);
  }
Пример #3
0
<?php
/**
 * Teste la sauvegarde d'équipes dans le backend
 * @author fabriceb
 * @since Feb 16, 2009 fabriceb
 */
include(dirname(__FILE__).'/../bootstrap/unit.php');

$t = new lime_test(11, new lime_output_color());

$t->diag('GMapClient Tests');
$gMapClient = new GMapClient('test');

$t->diag('->getApiKey');
$t->is($gMapClient->getAPIKey(),'test','key returned well');

$t->diag('->setApiKey');
$gMapClient->setAPIKey('test2');
$t->is($gMapClient->getAPIKey(),'test2','key returned well');

$t->diag('->getGoogleJsUrl');
$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);
Пример #4
0
<?php

/**
 * Teste la sauvegarde d'équipes dans le backend
 * @author fabriceb
 * @since Feb 16, 2009 fabriceb
 */
include dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new lime_test(11, new lime_output_color());
$t->diag('GMapClient Tests');
$gMapClient = new GMapClient('test');
$t->diag('->getApiKey');
$t->is($gMapClient->getAPIKey(), 'test', 'key returned well');
$t->diag('->setApiKey');
$gMapClient->setAPIKey('test2');
$t->is($gMapClient->getAPIKey(), 'test2', 'key returned well');
$t->diag('->getGoogleJsUrl');
$t->is($gMapClient->getGoogleJsUrl(false), 'http://maps.google.com/maps/api/js?sensor=false', 'getGoogleJsUrl working');
$t->is($gMapClient->getGoogleJsUrl(true), 'http://maps.google.com/maps/api/js?sensor=false', 'getGoogleJsUrl working');
$t->is($gMapClient->getGoogleJsUrl(), 'http://maps.google.com/maps/api/js?sensor=false', '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>
<?php

/**
 * Teste la sauvegarde d'équipes dans le backend
 * @author fabriceb
 * @since Feb 16, 2009 fabriceb
 */
include dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new lime_test(15, new lime_output_color());
$t->diag('GMapGeocodedAddress Tests');
$gAddress = new GMapGeocodedAddress('60 rue de Seine, Paris');
$t->diag('->getRawAddress');
$t->is($gAddress->getRawAddress(), '60 rue de Seine, Paris', '->getRawAddress ok');
require_once dirname(__FILE__) . '/../../lib/GMapClientTestCache.class.php';
$gMapClient = new GMapClient('test');
$gMapClientTestCache = new GMapClientTestCache();
$gMapClient->setCache($gMapClientTestCache);
$t->diag('->geocode');
$t->is($gAddress->geocode($gMapClient), 8, 'Geocoded returned accuracy 8');
$t->is($gAddress->getLat(), 48.853795, 'Lat ok');
$t->is($gAddress->getLng(), 2.3369433, 'Lng ok');
$t->is($gAddress->getAccuracy(), 8, 'Accuracy ok');
$t->is($gAddress->geocodeXml($gMapClient), 8, 'Geocoded returned accuracy 8');
$t->is($gAddress->getLat(), 48.853795, 'Lat ok');
$t->is($gAddress->getLng(), 2.3369433, 'Lng ok');
$t->is($gAddress->getAccuracy(), 8, 'Accuracy ok');
$t->is($gAddress->getGeocodedAddress(), '60 Rue de Seine, 75006 Paris, France', 'Normalized address ok');
$t->is($gAddress->getGeocodedCity(), 'Paris', 'Normalized City ok');
$t->is($gAddress->getGeocodedCountry(), 'France', 'Normalized Country ok');
$t->is($gAddress->getGeocodedCountryCode(), 'FR', 'Normalized Country code ok');
$t->is($gAddress->getGeocodedPostalCode(), '75006', 'Normalized postal code ok');