asp.net-mvc - 从 ZipCode 中检索 Lat Long
问题描述
他们是通过 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
解决方案
从您问题中的示例中,我假设您希望在自己的服务器上使用查找表,而不是使用任何 API。
Github上的Maxmind 库之一 可能包含此功能。然而,Maxmind City DB 实际上使用来自geonames.org的邮政编码数据,一个更简单的解决方案可能是将美国的GeoNames“查找”表Zip 上传到您的服务器。
它包含一个制表符分隔的文件(有关完整描述,请参见链接底部),您只需编写代码以通过邮政编码查找记录,然后从中读取经纬度字段。为了提高速度,您可以将文件导入 DBMS,例如 mySQL(google for instructions),并使用邮政编码作为键/索引。
我不知道 Geonames 数据的准确性和准确性。
推荐阅读
- python - 修复 INIT AND QUIT 的 no 模块后,我的 Vs pygame 仍然不显示突出显示
- python - Dask - 新集群创建失败,“dask”用户欠 HDFS 文件
- python - 我如何理解这个 Python “def”代码?
- compiler-errors - OpenBugs:扫描了无效或意外的令牌
- mysql - mamp phpmyadmin 错误脚本导入数据库
- css - 放置在 iframe 中时,闪亮的表格会失去居中
- ajax - 如何通过 ajax 进行分页使用正确的分页链接,而不是像 admin-ajax.php/page/n 这样的东西?
- python-3.x - 如何使用 Tor 和 stem 更新 IP
- arrays - 获取 C 数组中的项目数
- r - 按周期对数据框中的数据进行分组