谷歌反向地理编码,从latlng获取城市/国家
目前,我正在向 https://maps.googleapis.com/maps/api/geocode/json?key=API_KEY&latlng=48.866667,2.333333
发出 API 请求,其中 latlng
先谢谢各位同事了!
Currently I am making an API request to https://maps.googleapis.com/maps/api/geocode/json?key=API_KEY&latlng=48.866667,2.333333
where the latlng is the geo-point of Paris,France. What filters exactly do I have to pass in the request to get the Paris/France (city/country) as response for the specified latitude and longitude?
Thank you in advance colleagues!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你只想要国家/城市,谷歌就有点大材小用了。 3geonames.org 更快,并且它是免费的 api(不需要 api 密钥)。
https://api.3geonames.org/48.866667,2.333333
Google is a bit of an overkill if you only want country/city. 3geonames.org is faster and it is free api (no api key needed).
https://api.3geonames.org/48.866667,2.333333
根据 Google 文档:https://developers.google.com /maps/documentation/geocoding/requests-reverse-geocoding#optional_parameters
您可以在查询字符串中传递
result_type
进行过滤国家、州、城市、其他行政级别,包括公园和街道。请参阅文档中的不同result_types
示例:https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452 &location_type=ROOFTOP&result_type= street_address&key=YOUR_API_KEY
在您的 响应 JSON,位于
address_components 字段,您可以查看结果并进一步筛选特定内容。
As per Google's Documentation: https://developers.google.com/maps/documentation/geocoding/requests-reverse-geocoding#optional_parameters
You can pass
result_type
in the query string to filter by country, states, city, other administrative levels, including park and street. See the differentresult_types
in documentation Example:https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452 &location_type=ROOFTOP&result_type=street_address&key=YOUR_API_KEY
In your response JSON, inside
address_components
field, you can view the results and filter it further for something specific.确保您具有所需的参数。
latlng:将此视为您的秘密代码,用于告诉地图您所在的位置。这就像向其提供您所在位置的准确 GPS 号码(纬度和经度)。
key:这就像你的地图通行证。这是一个特殊的键,可以告诉地图您正在请求此信息。它有助于跟踪您使用地图服务的情况。您可以在说明中了解如何获取此密钥。
这是来自Google的API文档
Make sure you have the required Parameters.
latlng: Think of this as your secret code to tell the map where you are. It's like giving it the exact GPS numbers (latitude and longitude) of your location.
key: This is like your map pass. It's a special key that tells the map it's you asking for this information. It helps keep track of how much you use the map service. You can learn how to get this key in the instructions.
This is from API documentation of Google