Piwik\Plugins\UserCountry\API::getLocationFromIP PHP Метод

getLocationFromIP() публичный Метод

See LocationProvider::getLocation to see the details of the result of this function.
public getLocationFromIP ( string $ip, boolean | string $provider = false ) : array | false
$ip string The IP address.
$provider boolean | string The ID of the provider to use or false to use the currently configured one.
Результат array | false
    public function getLocationFromIP($ip, $provider = false)
    {
        Piwik::checkUserHasSomeViewAccess();
        if (empty($provider)) {
            $provider = LocationProvider::getCurrentProviderId();
        }
        $oProvider = LocationProvider::getProviderById($provider);
        if (empty($oProvider)) {
            throw new Exception("Cannot find the '{$provider}' provider. It is either an invalid provider " . "ID or the ID of a provider that is not working.");
        }
        $location = $oProvider->getLocation(array('ip' => $ip));
        if (empty($location)) {
            throw new Exception("Could not geolocate '{$ip}'!");
        }
        $location['ip'] = $ip;
        return $location;
    }