コード例 #1
0
        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");
        }
コード例 #2
0
 public void LocateAddress(IPAddress address)
 {
     Logger.LogTrace($"address=|{address.ToString()}|");
     if (!IPAddress.IsLoopback(address))
     {
         try
         {
             GeolocationParams geoParams = new GeolocationParams();
             geoParams.SetIp(address.ToString());
             geoInfo = Api.GetGeolocation(geoParams);
             if (geoInfo.GetStatus() != (int)HttpStatusCode.OK)
             {
                 Logger.LogError(geoInfo.GetMessage());
             }
         } catch (Exception e)
         {
             Logger.LogError($"Can't initialize IPGeolocation: |{e.Message}|");
         }
     }
 }