他们是通过 ZipCode 而不是 Ipaddress从MaxmindDb获取 Lat Long 的一种方式。因为我找不到任何通过邮政编码获取详细信息的方法。我不想使用 Google Maps 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