他们是通过ZipCode而不是Ipaddress从MaxmindDb获得Lat Long的方法。因为我找不到任何通过zipcode获取细节的方法。我不想使用谷歌地图Api。
using (var reader = new DatabaseReader(System.Web.Hosting.HostingEnvironment.MapPath("~/GeoLite2-City.mmdb")))
{
var city = reader.City(userIpAddress);
string cityiso = string.Empty;
if (city != null && !string.IsNullOrEmpty(city.City.Name) && !string.IsNullOrEmpty(city.MostSpecificSubdivision.IsoCode))
{
cityiso = string.Join(", ", city.City.Name, city.MostSpecificSubdivision.IsoCode);
}
locationProperties.Location = cityiso;
locationProperties.Latitude = city.Location.Latitude.ToString();
locationProperties.Longitude = city.Location.Longitude.ToString();
}
但我想使用UserZipCode而不是UserIPAddress
从您问题中的示例我假设您想要在您自己的服务器上查找表而不是使用任何API。
其中一个Maxmind Libraries on Github可能包含此功能。但Maxmind City DB实际上使用geonames.org的邮政编码数据,更简单的解决方案可能是将美国的GeoNames "look-up" table Zip上传到您的服务器。
它包含一个制表符分隔文件(请参阅链接底部以获取完整描述),您只需编写代码以通过邮政编码查找记录,然后从中读取lat和long字段。为了提高速度,您可以将文件导入DBMS,例如mySQL(谷歌的说明),邮政编码为密钥/索引。
我不知道Geonames数据的准确性和准确性。