【问题标题】:Retrive Lat Long from ZipCode从邮政编码中检索经纬度
【发布时间】:2019-02-21 06:20:21
【问题描述】:

他们是通过 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

【问题讨论】:

  • 如果他们的web site resources 没有回答您的问题,这几乎是一个产品支持问题。这假设您必须使用 Maxmind(相对于 Maxmind 专注于地理位置与安全/IP 焦点的任何其他服务)
  • 我在他们的论坛上提出了问题,但我没有提出我的要求。

标签: asp.net-mvc geoip maxmind geoip2 geolite2


【解决方案1】:

根据您问题中的示例,我假设您希望在自己的服务器上使用查找表,而不是使用任何 API。

Maxmind Libraries on Github 之一可能包含此功能。但是 Maxmind City DB 实际上使用来自 geonames.org 的邮政编码数据,更简单的解决方案可能是将美国的 GeoNames "look-up" table Zip 上传到您的服务器。

它包含一个制表符分隔的文件(完整描述请参见链接底部),您只需编写代码以通过邮政编码查找记录,然后从中读取经纬度字段。为了提高速度,您可以将文件导入 DBMS,例如以邮政编码作为键/索引的 mySQL(google 获取说明)。

我不知道 Geonames 数据的准确性和准确性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    相关资源
    最近更新 更多