查找纬度/经度的县名称

发布于 2024-11-04 20:28:08 字数 1803 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

绳情 2024-11-11 20:28:09

另一种选择:

  • http://download.geonames.org/export/dump/
  • 将每个城市添加为纬度/经度 ->将国家/地区映射到空间索引,例如 R 树(某些数据库也具有该功能)
  • 使用最近邻搜索来查找与任何给定点的最近人类住区相对应的国家/地区

优点:

  • 不依赖于外部服务器可用
  • 速度更快(每秒轻松进行数千次查找)

缺点:

  • 可能会在边界附近给出错误答案,尤其是在人口稀少的地区

Another option:

  • Download the cities database from http://download.geonames.org/export/dump/
  • Add each city as a lat/long -> Country mapping to a spatial index such as an R-Tree (some DBs also have the functionality)
  • Use nearest-neighbour search to find the country corresponding to the closest human settlement for any given point

Advantages:

  • Does not depend on aa external server to be available
  • Much faster (easily does thousands of lookups per second)

Disadvantages:

  • May give wrong answers close to borders, especially in sparsely populated areas
少女七分熟 2024-11-11 20:28:09

您可能想看看 Tiger data 并查看其属性中是否包含包含县名的多边形。如果它是 Java Geotools API 可让您处理这些数据。您将对县多边形执行多边形中的点查询,然后进行要素属性查找。

You may want to have look at Tiger data and see if it has polygons containing the county name in an attribute. If it does the Java Geotools API lets you work with this data. You will be performing point in polygon queries for the county polygons followed by a feature attribute look-up.

狼亦尘 2024-11-11 20:28:09

也许这是一个很好的解决方案。它是 json 格式。我总是在我的项目中使用它。

http://maps.google.com/maps/geo?ll=10.345561,123.896932

并使用php简单地提取信息。

$x = file_get_contents("http://maps.google.com/maps/geo?ll=10.345561,123.896932");

$j_decodex = json_decode($x);

print_r($j_decodex);

Maybe this is a great solution.It is in a json format.I always use this in my projects.

http://maps.google.com/maps/geo?ll=10.345561,123.896932

And simply extract the information using php.

$x = file_get_contents("http://maps.google.com/maps/geo?ll=10.345561,123.896932");

$j_decodex = json_decode($x);

print_r($j_decodex);
多像笑话 2024-11-11 20:28:08

为了完整起见,我找到了另一个非常简单的 API 来获取这些数据,所以我想分享一下。

https://geo.fcc.gov/api/census/

FCC 提供了一个 Block API正是针对这个问题,它使用人口普查数据来执行查找。

他们的使用限制政策是(来自[电子邮件受保护]

我们对块转换 API 没有任何使用限制,但我们确实要求您尽可能分散请求。

Just for completeness, I found another API to get this data that is quite simple, so I thought I'd share.

https://geo.fcc.gov/api/census/

The FCC provides an Block API for exactly this problem and it uses census data to perform the look up.

Their usage limit policy is (From [email protected])

We do not have any usage limits for the block conversion API, but we do ask that you try to spread out your requests over time if you can.

奶茶白久 2024-11-11 20:28:08

Google 确实会为您的示例填充县,

http://maps.googleapis.com/maps/api/geocode/json?latlng=39.76144296429947,-104.8011589050293&sensor=false

在响应中,查看键 下方地址组件其中包含代表“Adams”县的对象,

{
    long_name: "Adams"
    short_name: "Adams"
    -types: [
        "administrative_area_level_2"
        "political"
    ]
}

这里是来自地理编码 API 的文档

administrative_area_level_2表示国家级以下的二级民事实体。 在美国,这些行政级别是县。并非所有国家/地区都显示这些行政级别。

Google does populate the county for your example,

http://maps.googleapis.com/maps/api/geocode/json?latlng=39.76144296429947,-104.8011589050293&sensor=false

In the response, look under the key address_components which contains this object representing "Adams" county,

{
    long_name: "Adams"
    short_name: "Adams"
    -types: [
        "administrative_area_level_2"
        "political"
    ]
}

Here's from the Geocoding API's docs,

administrative_area_level_2 indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文