本文介绍了将Google Places自动填充API限制为特定国家/地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个基于Titanium的移动应用程序,我想在其中显示地址自动完成建议.我可以在应用中使用当前位置和半径获取自动完成建议,但我想将这些结果限制在特定的国家或地区.

I am implementing a Titanium based mobile application in which I want to show address autocomplete suggestions. I am able to get the autocomplete suggestion in my app with current position and radius but I want to restrict those results to specific country or countries.

我通过附加如下所示的参数来创建URL:

I am creating a URL by appending parameters which looks like this:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input = 110 Ward& location = 40.7128,-74.0059& radius = 500& types = address& key = XXXXXXXXXXXXXXX

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=110 Ward&location=40.7128,-74.0059&radius=500&types=address&key=XXXXXXXXXXXXXXX

URL位置是坐标(中心),半径是距坐标(中心)的距离,输入是显示自动完成建议的文本.

In the URL location are coordinates (center), radius is distance from coordinates (center) and input is the text upon which autocomplete suggestions are shown.

所以这是如何工作的:1.如果在从当前位置开始的指定半径内有某个地址,它将显示在建议地址的顶部.2.如果提供的半径中没有地址,但是该半径之外的地址可用,则会显示这些地址,因为我没有使用API​​的strictBounds属性.

So how this works is:1. If there is some address present in specified radius from current position it will be shown on the top of suggested address.2. If there is no address present in provided radius but address are available outside the radius, those address will be shown because I am not using strictBounds property of API.

我要的是,如果基于用户输入的地址在指定半径范围内不可用,它应该显示半径范围之外的匹配地址,但不在指定国家/地区之外.

What I want is I if address based on user input are not available in specified radius it should show matching addresses outside the radius but NOT outside the specified country.

如何在此URL中附加一个或多个特定国家/地区.

How can I append the specific country or countries in this URL.

谢谢.

推荐答案

您可以使用文档.

您最多可以在组件过滤器中设置5个国家/地区.例如,要显示来自美国和加拿大的结果:

You can set up to 5 countries in components filter. For example, to show results from the USA and Canada:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=110%20Ward&location=40.7128%2C-74.0059& radius = 500& types = address& components = country%3ACA%7Ccountry%3AUS& key = YOUR_API_KEY

这篇关于将Google Places自动填充API限制为特定国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:32