getDataResult
abstract public function getDataResult( $ip, $lang = '' );
Non-static abstract method returns result with geolocation data - class \Bitrix\Main\Service\GeoIp\Result if it was defined or returns null otherwise.
Parameter | Description | Available from version |
---|---|---|
ip | IP address | |
lang | Language ID |
Examples
Get all available data directly:
$geoResult = GeoIp\Manager::getDataResult('92.50.195.50'); if($geoResult) { if($geoResult->isSuccess()) var_dump($geoResult->getGeoData()); elseif(!$geoResult->isSuccess()) echo "Ошибка: ".implode("
\n", $geoResult->getErrorMessages()); } else { echo 'No data for this IP address'; }
Returned result is an object - data structure \Bitrix\Main\Service\GeoIp\Data
:
>>object(Bitrix\Main\Service\GeoIp\Data)[97] public 'ip' => string '92.50.195.50' (length=12) public 'lang' => string 'en' (length=2) public 'countryName' => string 'New York' (length=6) public 'regionName' => string 'New York' (length=6) public 'subRegionName' => GeoIp\Manager::INFO_NOT_AVAILABLE public 'cityName' => string 'New York' (length=6) public 'countryCode' => string 'US' (length=2) public 'regionCode' => string 'US-NYC' (length=6) public 'zipCode' => GeoIp\Manager::INFO_NOT_AVAILABLE public 'latitude' => float 55.75222 public 'longitude' => float 37.61556 public 'timezone' => string 'USA/New York' (length=13) public 'asn' => GeoIp\Manager::INFO_NOT_AVAILABLE public 'ispName' => GeoIp\Manager::INFO_NOT_AVAILABLE public 'organizationName' => GeoIp\Manager::INFO_NOT_AVAILABLE public 'handlerClass' => string 'Bitrix\Main\Service\GeoIp\SypexGeo' (length=34)
When there is no data - returns GeoIp\Manager::INFO_NOT_AVAILABLE
.
When you need strictly specific language and specific time:
$geoResult = GeoIp\Manager::getDataResult('92.50.195.50', 'en', array('countryName', 'cityName'));
© «Bitrix24», 2001-2024