Beispiel #1
0
 protected function makeFromJSON($_json)
 {
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "entering");
     $gadc = new GeoGadc();
     $gadc->short_name = $_json['short_name'];
     $gadc->long_name = $_json['long_name'];
     $gadc->types = $_json['types'];
     sort($gadc->types);
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "leaving");
     return $gadc;
 }
Beispiel #2
0
 protected function makeFromJSON($_json)
 {
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "entering");
     $gdat = new GeoGdat();
     $geomfactory = new GeoGeomFactory();
     $gadcfactory = new GeoGadcFactory();
     $gdat->geometry = $geomfactory->make(new JSONGeoGeomFactoryData($_json['geometry']));
     $gdat->formatted_address = $_json['formatted_address'];
     $gdat->types = $_json['types'];
     $gdat->lang = $_json['lang'];
     $gdat->ext = 0;
     foreach ($_json['address_components'] as $ad) {
         $gdat->address_components[] = $gadcfactory->make(new JSONGeoGadcFactoryData($ad));
     }
     return $gdat;
 }
Beispiel #3
0
 public function reverseGeocode($_lat, $_lng, $_lang)
 {
     GeoProxy::log(LOG_NOTICE, __CLASS__, __FUNCTION__, "asking for: [{$_lat}:{$_lng}] ({$_lang})");
     $headers = array("Host: maps.google.com");
     $url = sprintf('http://%s/maps/api/geocode/json?sensor=%s&latlng=%s,%s&language=%s', GOOGLE_MAPS_SERVER . ":" . GOOGLE_MAPS_PORT, 'false', $_lat, $_lng, $_lang);
     if (GOOGLE_MAPS_SIGN) {
         $url .= "&client=" . GOOGLE_MAPS_ID;
         $url = self::signUrl($url, GOOGLE_MAPS_KEY);
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "url signing requested, url is now: [" . $url . "]");
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     if (!($json = curl_exec($ch))) {
         GeoProxy::log(LOG_CRIT, __CLASS__, __FUNCTION__, "Curl error: " . curl_errno($ch));
         curl_close($ch);
         return $result = array();
     }
     $google = json_decode($json, true);
     switch ($google['status']) {
         case "OK":
             GeoProxy::log(LOG_INFO, __CLASS__, __FUNCTION__, "data found in google");
             curl_close($ch);
             return $google['results'];
         case "OVER_QUERY_LIMIT":
             GeoProxy::log(LOG_CRIT, __CLASS__, __FUNCTION__, "OVER_QUERY_LIMIT reached !");
             break;
         case "ZERO_RESULTS":
             GeoProxy::log(LOG_WARNING, __CLASS__, __FUNCTION__, "ZERO_RESULTS found !");
             break;
         default:
             GeoProxy::log(LOG_WARNING, __CLASS__, __FUNCTION__, "Google unknown status: " . $google->status);
     }
     curl_close($ch);
     return $result = array();
 }
Beispiel #4
0
 public function equals($_gadc)
 {
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "entering");
     if (!($_gadc->short_name = $this->short_name)) {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "leaving (false 1)");
         return false;
     }
     if (!($_gadc->long_name = $this->long_name)) {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "leaving (false 2)");
         return false;
     }
     if (count($_gadc->types) != count($this->types)) {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "leaving (false 3)");
         return false;
     }
     $s1 = array_diff($_gadc->types, $this->types);
     if (count($s1) > 0) {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "leaving (false 4)");
         return false;
     }
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "leaving (true)");
     return true;
 }
Beispiel #5
0
 protected function makeFromJSON($_json)
 {
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "entering");
     $geom = new GeoGeom();
     $geom->location_type = $_json['location_type'];
     $geom->location = new GeoLocation($_json['location']['lat'], $_json['location']['lng']);
     if (isset($_json['viewport'])) {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "viewport exists in array, propagating to object");
         $sw = new GeoLocation($_json['viewport']['southwest']['lat'], $_json['viewport']['southwest']['lng']);
         $ne = new GeoLocation($_json['viewport']['northeast']['lat'], $_json['viewport']['northeast']['lng']);
         $geom->viewport = new GeoBounds($sw, $ne);
     } else {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "viewport doesn't exist in array");
     }
     if (isset($_json['bounds'])) {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "bounds exists in array, propagating to object");
         $sw = new GeoLocation($_json['bounds']['southwest']['lat'], $_json['bounds']['southwest']['lng']);
         $ne = new GeoLocation($_json['bounds']['northeast']['lat'], $_json['bounds']['northeast']['lng']);
         $geom->bounds = new GeoBounds($sw, $ne);
     } else {
         GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "bounds doesn't exist in array");
     }
     return $geom;
 }
Beispiel #6
0
 public function __construct()
 {
     parent::__construct();
     $this->proxy = GeoProxy::getInstance();
 }
Beispiel #7
0
 public function indexGdatID($_gdatid, $_indexname, $_indexvalue)
 {
     $key = "idx:gdat" . $this->mapF2I($_indexname) . ":" . $_indexvalue;
     $this->writeConn->sAdd($key, $_gdatid);
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "index [{$_indexname}:{$_indexvalue}] updated with gdat:id=[{$_gdatid}]");
 }
Beispiel #8
0
 public function computeSerial()
 {
     $md5 = md5(serialize($this));
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "computed value: {$md5}");
     return $md5;
 }
Beispiel #9
0
 public function __construct()
 {
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "leaving");
 }
Beispiel #10
0
 public function getGdatIDs($_filters)
 {
     $filternames = array_keys($_filters);
     $nbfilters = count($filternames);
     $keys = array();
     if (in_array('query', $filternames) && (in_array('lng', $filternames) or in_array('lat', $filternames))) {
         // query can not be specified with lat and/or lng in the same time
         throw new Exception('filter with both query and lat/lng');
     }
     $logbuf = "";
     foreach ($filternames as $filtername) {
         $logbuf .= " {$filtername}=[" . $_filters[$filtername] . "]";
     }
     GeoProxy::log(LOG_DEBUG, __CLASS__, __FUNCTION__, "received query filter with {$logbuf}");
     if (!in_array('lang', $filternames)) {
         // default language == en
         $_filters['lang'] = 'en';
     }
     // first case: geocoding
     if (in_array('query', $filternames)) {
         // encode query
         $_filters['query'] = rawurlencode($_filters['query']);
         $this->geocodeData($_filters['query'], $_filters['lang']);
     } elseif (in_array('lat', $filternames) && in_array('lng', $filternames)) {
         //second case: reverse geocoding
         $this->reverseGeocodeData($_filters['lat'], $_filters['lng'], $_filters['lang']);
     }
     // at the end, search in Redis
     return $this->rq->search("gdat", $_filters);
 }