从googleapi自动完成请求中获取拉链

发布于 2025-01-25 01:13:43 字数 1094 浏览 3 评论 0原文

我将以下请求发送给Google Autococtlete API,以尝试获取包含邮政编码的街道地址。

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=917&component=country:us&key=[MyApiKey]&types=address&bounds=defaultBounds&stricktBounds=true&address_components=postal_code&fields=address_components

我似乎无法弄清楚如何在查询参数中询问邮政编码。当我通过输入中的ZIP传递完整地址时,Google返回邮政编码,但我希望它始终返回邮政编码。

我可以向Google Maps API提出另一个请求,并传递我从Autococtlete Endpt获得的位置ID,并通过以下请求获取完整的地址。

https://maps.googleapis.com/maps/api/place/details/json?fields=formatted_address&place_id=Eic1MDEgQ29sbGVnZSBBdmVudWUsIEdyZWVuc2Jvcm8sIE5DLCBVU0EiURJPCjQKMgldGdoYQBlTiBEjv0Tw4tNAARoeCxDuwe6hARoUChIJVXM4RSQZU4gRLNRdpst7vxAMEPUDKhQKEgmVWLxpQBlTiBGKDjnnY2NAzg&key=[my_Key]

但是我想进行搜索,并在一个请求中获取邮政编码。

编辑: 以下使用Google API JavaScript软件包在JavaScript中工作,但我无法在项目中使用JavaScript ...

https://maps.googleapis.com/maps/api/place/js/AutocompletionService.GetPredictions?1s501&fields=formatted_address&key=[my_key]

谢谢您的任何帮助!

I am sending the following request to the google autocomplete api in attempts to get a street address with the zip code included.

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=917&component=country:us&key=[MyApiKey]&types=address&bounds=defaultBounds&stricktBounds=true&address_components=postal_code&fields=address_components

I can't seem to figure out how to ask for the zip code in the query parameters. When I pass a full address with the zip in the input, google returns the zip code, but I would like it to always return the zip code.

I can make another request to the google maps api and pass the place id that I get from the autocomplete endpt and get the full address with the following request.

https://maps.googleapis.com/maps/api/place/details/json?fields=formatted_address&place_id=Eic1MDEgQ29sbGVnZSBBdmVudWUsIEdyZWVuc2Jvcm8sIE5DLCBVU0EiURJPCjQKMgldGdoYQBlTiBEjv0Tw4tNAARoeCxDuwe6hARoUChIJVXM4RSQZU4gRLNRdpst7vxAMEPUDKhQKEgmVWLxpQBlTiBGKDjnnY2NAzg&key=[my_Key]

But I would like to do a search and get the zip code all in one request.

Edit:
The following works in javascript with the google api javascript package, but I cannot use javascript in my project...

https://maps.googleapis.com/maps/api/place/js/AutocompletionService.GetPredictions?1s501&fields=formatted_address&key=[my_key]

Thanks for any help!!

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

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

发布评论

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

评论(1

甜柠檬 2025-02-01 01:13:43

Google API Place TextSearch端点可以与字段类型ford_address一起使用以返回邮政编码。

https://maps.googleapis.com/maps/api/place/textsearch/json?query=971&fields=formatted_address&inputtype=textquery&key=[my_key]

The google api place textsearch endpoint can be used instead with field type formatted_address to return the zip code.

https://maps.googleapis.com/maps/api/place/textsearch/json?query=971&fields=formatted_address&inputtype=textquery&key=[my_key]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文