我正在使用一种从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对象具有以下属性:
Region
,RegionName
,CountryCode
,City
,Postal Code
,Latitude
,Longitude
。但是,我需要州和县。如何从所获得的信息中获得州和县? 最佳答案
使用Census Block Conversions API完成此操作。
例如:
http://data.fcc.gov/api/block/find?format=json&latitude=28.35975&longitude=-81.421988&showall=true
关于c# - GeoIpLocation-如何获取州和县? (或者,如何从邮政编码获取州和县)C#,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37217923/