public string GetLocation(string ip) { IPGeolocationAPI api = new IPGeolocationAPI("7461e5a511964d22ac7310cf8a9e4f02"); GeolocationParams geoParams = new GeolocationParams(); geoParams.SetIp(ip); Geolocation geolocation = api.GetGeolocation(geoParams); if (geolocation.GetStatus() == 200) { var location = geolocation.GetCity(); repo.UpdateLocation(Current_idUser, location); return(location); } return("Default"); }
public static void GetLocation() { // Create IPGeolocationAPI object, passing your valid API key IPGeolocationAPI api = new IPGeolocationAPI("7f568c0011f94605ab23aac3e1aa3ea6"); // Get geolocation for IP address and fields GeolocationParams geoParams = new GeolocationParams(); geoParams.SetIPAddress("172.220.225.50"); geoParams.SetFields("geo,time_zone,currency"); Geolocation geolocation; try { geolocation = api.GetGeolocation(geoParams); // Check if geolocation lookup was successful if (geolocation.GetStatus() == 200) { Console.WriteLine("Last Know Location: "); Console.WriteLine(geolocation.GetTimezone().GetCurrentTime()); Console.WriteLine("\nCountry: " + geolocation.GetCountryName()); Console.WriteLine("State/Province: " + geolocation.GetStateProvince()); Console.WriteLine("City: " + geolocation.GetCity()); Console.WriteLine("Lat: " + geolocation.GetLatitude()); Console.WriteLine("Long: " + geolocation.GetLongitude()); } else if (geolocation.GetStatus() != 200) { Console.WriteLine("Data cannot be retrieved."); } } catch { Console.WriteLine("Cannot retrieve data."); } Console.ReadKey(); }
protected override Task <Location> GetLocationByIpInner(string ipAddress) { var api = new IPGeolocationAPI(ApiKey); var geoParams = new GeolocationParams(); geoParams.SetIp(ipAddress); var geolocation = api.GetGeolocation(geoParams); if (geolocation.GetStatus() != 200) { throw new Exception(); } return(Task.FromResult(new Location() { City = geolocation.GetCity(), Country = geolocation.GetCountryName(), Latitude = double.Parse(geolocation.GetLatitude(), System.Globalization.CultureInfo.InvariantCulture), Longitude = double.Parse(geolocation.GetLongitude(), System.Globalization.CultureInfo.InvariantCulture) })); }
public IpGeoLocation(IConfiguration configuration, ILogger <IpGeoLocation> logger) { Logger = logger; Logger.LogDebug($"IpGeoLocationAPIKey=|{configuration.GetValue<string>("IpGeoLocationAPIKey")}|"); Api = new IPGeolocationAPI(configuration.GetValue <string>("IpGeoLocationAPIKey")); }