/** * * @param type $strConfig * @param GeolocationContainer $objGeolocation * @return boolean|\GeolocationContainer */ public function getLocation($strConfig, GeolocationContainer $objGeolocation) { $objRequest = new Request(); $objRequest->send(vsprintf($strConfig, array($objGeolocation->getLat(), $objGeolocation->getLon()))); if ($objRequest->code != 200) { $this->log("Error by location service: " . vsprintf("Request error code %s - %s ", array($objRequest->code, $objRequest->error)), __CLASS__ . " | " . __FUNCTION__, __FUNCTION__); return false; } $arrJson = json_decode($objRequest->response, true); if (!is_array($arrJson)) { $this->log("Response is not a array.", __CLASS__ . " | " . __FUNCTION__, __FUNCTION__); return false; } $arrCountries = $this->getCountries(); $strCountryShort = $arrJson['address']['country_code']; $strCounty = $arrCountries[$arrJson['address']['country_code']]; $objGeolocation->setCountryShort($strCountryShort); $objGeolocation->setCountry($strCounty); return $objGeolocation; }
/** * User lookup services to get information about a lat/lon value * * @param GeolocationContainer $objGeolocation * @return boolean|GeolocationContainer Fales if no result else a GeolocationContainer * @throws Exception */ public function doGeoLookUP(GeolocationContainer $objGeolocation) { // Split $arrLat = trimsplit(".", $objGeolocation->getLat()); $arrLon = trimsplit(".", $objGeolocation->getLon()); // Check if we have two values if (count($arrLat) != 2 || count($arrLon) != 2) { return false; } // Try to loat information from lookup services $arrLookUpServices = deserialize($GLOBALS['TL_CONFIG']['geo_GeolookUpSettings']); $objGeolocationResult = FALSE; // Run trough each service foreach ($arrLookUpServices as $value) { $objLookUpService = GeoLookUpFactory::getEngine($value["lookUpClass"]); $objGeolocationResult = $objLookUpService->getLocation($value["lookUpConfig"], $objGeolocation); if ($objGeolocationResult !== FALSE) { $objGeolocation = $objGeolocationResult; break; } } // Check if we have a positive result form one of the lookup services if ($objGeolocationResult === FALSE) { return false; } else { $objGeolocation->setTracked(true); $objGeolocation->setTrackType(GeolocationContainer::LOCATION_W3C); $objGeolocation->addTrackFinished(GeolocationContainer::LOCATION_W3C); $objGeolocation->setTrackRunning(GeolocationContainer::LOCATION_NONE); $objGeolocation->setFailed(false); $objGeolocation->setError(""); $objGeolocation->setErrorID(GeolocationContainer::ERROR_NONE); } return $objGeolocation; }