【问题标题】:GeoIpLocation - How to get State and County? (OR, how to get State and County from a zip code) C#GeoIpLocation - 如何获取州和县? (或者,如何从邮政编码中获取州和县)C#
【发布时间】:2016-05-13 19:27:27
【问题描述】:

我正在使用一种方法从 IP 地址获取 IipLocation 对象。这是返回 Location 对象的代码:

public IIpLocation GetIpLocation(IPAddress ipAddress)
{
    ipAddress.CheckNull("ipAddress");

    IIpLocation ipLocation = null;
    try
    {
        //Try to look up the location using MaxMind.
        Location location = GetMaxMindIpLocation(ipAddress);

        //If the postal code is not present, then try to look it up with GeoNames.
        if (location != null && (location.PostalCode == null || location.PostalCode.Equals("")))
        {
            location.PostalCode = GetPostalCodeFromGeoNames(location);
        }

        if (location != null)
        {
            ipLocation = new GeoIpLocation(location);
        }
    }
    catch (NullReferenceException)
    {
        Log.ErrorFormat(Resources.log_maxMindLookupFailed, ipAddress);
    }

    return ipLocation;
}

IipLocation 对象具有以下属性:RegionRegionNameCountryCodeCityPostal CodeLatitudeLongitude。但是,我需要州和县。如何从我拥有的信息中获取州和县?

【问题讨论】:

  • 我有点困惑。 GetMaxMindIpLocation() 来自哪里? MaxMind's official API 拥有您要查找的所有数据。

标签: c# geolocation location geoip


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-27
  • 2013-04-05
  • 2022-12-13
  • 1970-01-01
  • 2018-07-23
  • 1970-01-01
  • 2017-04-05
相关资源
最近更新 更多