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;
}