43 $url =
'http://api.sypexgeo.net/';
50 $httpRes = $httpClient->get($url);
51 $errors = $httpClient->getError();
53 if (!$httpRes && !empty($errors))
57 foreach($errors as $errorCode => $errMes)
58 $strError .= $errorCode.
": ".$errMes;
60 $result->addError(
new Error($strError));
64 $status = $httpClient->getStatus();
68 $result->addError(
new Error(
'Sypexgeo.net http status: '.$status));
72 $arRes = json_decode($httpRes,
true);
76 if(mb_strtolower(SITE_CHARSET) !=
'utf-8')
77 $arRes = Encoding::convertEncoding($arRes,
'UTF-8', SITE_CHARSET);
79 $result->setData($arRes);
83 $result->addError(
new Error(
'Can\'t decode json result'));
122 $geoData =
new Data();
124 $geoData->lang = $lang = $lang <>
'' ? $lang :
'en';
126 $key = !empty($this->config[
'KEY']) ? $this->config[
'KEY'] :
'';
129 if($res->isSuccess())
131 $data = $res->getData();
133 $geoData->countryName = $data[
'country'][
'name_'.$lang];
134 $geoData->countryCode = $data[
'country'][
'iso'];
135 $geoData->regionName = $data[
'region'][
'name_'.$lang];
136 $geoData->regionGeonameId = $data[
'region'][
'id'];
137 $geoData->regionCode = $data[
'region'][
'iso'];
138 $geoData->cityName = $data[
'city'][
'name_'.$lang];
139 $geoData->cityGeonameId = $data[
'city'][
'id'];
140 $geoData->latitude = $data[
'city'][
'lat'];
141 $geoData->longitude = $data[
'city'][
'lon'];
142 $geoData->timezone = $data[
'region'][
'timezone'];
144 if ($geoData->regionGeonameId && $geoData->regionName)
146 $geoData->geonames[$geoData->regionGeonameId][$lang] = $geoData->regionName;
149 if ($geoData->cityGeonameId && $geoData->cityName)
151 $geoData->geonames[$geoData->cityGeonameId][$lang] = $geoData->cityName;
156 $dataResult->addErrors($res->getErrors());
159 $dataResult->setGeoData($geoData);