gpt4 book ai didi

google-places-api - 从给定的城市谷歌地点 API 检索所有地点和子地点

转载 作者:行者123 更新时间:2023-12-04 19:33:20 25 4
gpt4 key购买 nike

我正在寻找 Web 服务或 Google Place API 类型的插件来检索给定城市名称的地点、子地点和区域。

一直在尝试使用 google 和 geonames,但无法通过它。

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=hyderabad&types=(locality)&language=en_US&key=My_KEY


https://maps.googleapis.com/maps/api/geocode/json?/?address=hyderabad&key=My_KEY

这两种方法都试过了。任何帮助,将不胜感激。

最佳答案

一个城市被定义为

locality indicates an incorporated city or town political entity.



和一个子区域为:

sublocality indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: sublocality_level_1 to sublocality_level_5.



address component types in geocoding .也应该引用 supported types to use的列表使用类型请求参数和 Google API 返回的参数。

这个想法是从您所在城市的指定 sublocality_level_1 开始,检索 sublocality_level_2s,将它们存储到 DB。重复,但这次只使用 sublocality_level_2 来获得 sublocality_level_3。关键是将几何和地址名称(长名称、短名称等)存储在数据库中,以便您可以再次运行它们以获取足够的信息(如果不是全部),从而模拟缩放行为。最后使用自动完成 API 来检索一个(子)位置,该位置未到达您的商店,但您知道应该检索到的。

替换 geocoding request 中的level_1 sublocality、locality 和level_1 管理区域json:

https://maps.googleapis.com/maps/api/geocode/xml?address=[sublocality.1],+[locality],+[admin_area_level.1]&key=API_KEY



验证 sublocality.1 是否位于正确的位置。
<address_component>
<long_name>sublocality.1</long_name>
<short_name>sublocality.1</short_name>
<type>sublocality_level_1</type>
<type>sublocality</type>
<type>political</type>
</address_component>
<..></..>
<..></..>
<geometry>
<location>
<lat>nn.nnnnnnnnn</lat>
<lng>nn.nnnnnnnnn</lng>
</location>

使用 Radar search带查询参数 location=&radius=10000&types=(regions)

引用 supported types

The (regions) type collection instructs the Places service to return any result matching the following types:



接下来是提取所有的place_id,使用 place details API它将 place_id 作为查询参数并需要一个 api_key。

place details响应应包含所选 sublocality_level_1 的所有 sublocality_level_2。将它们存储到数据库中,按名称省略重复项。最后,你有一个位置(城市),选择了 sublocality_level_1 和 sublocality_level_2 位置实体的数量。

这应该适用于 sublocality_level_2。我相信,由于它们占据了相当大的面积,因此理想情况下可能不会错过它们。如果您错过了,请使用 Autocomplete APIs如果您知道起始字符或 Reverse Geocoding如果您知道缺少的 level_2 的确切几何形状。

对已知名称的给定 level_2 下的 sublocality_level_3 重复上述步骤。

geometry使用 Reverse Geocoding获取 level_3,如果商店中不存在,则针对 Place details 运行,再次检索 sublocality_level_2 并存储。这是需要的,因为一些 level_3 直接关联到 level_1s。这一步类似于在 map 上仔细缩放以找到一个位置。

使用 JSON

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=&types=(regions)&location=latitude,longitude&radius=1000&key=YOUR_API_KEY



注意区域周围的 ()。这给了你地点和其他人。 Refer to https://developers.google.com/places/web-service/autocomplete

整个过程可以重复,sub_locality_type_1 与先前使用的相邻并位于同一位置。使用 nearby search (place search)为了这。 location 的查询参数应为上述 level_1(子)位置的西南和东北边界的几何图形。注意使用半径=1。使用的 JSON URI 是:

https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters

关于google-places-api - 从给定的城市谷歌地点 API 检索所有地点和子地点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32330117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com