【问题标题】:I want google maps API autocomplete to search towns in a specific city only我希望谷歌地图 API 自动完成功能仅搜索特定城市的城镇
【发布时间】:2018-01-24 00:22:11
【问题描述】:

我正在尝试使用谷歌地图 API 在输入字段中获取唯一的 Town Names。以下是我正在处理的图像。

Screenshot of my input fields

所以,我在第一个选择字段中输入了我所有的城市,并在第二个输入字段中使用了谷歌地图自动完成 API。我已经对其使用了国家/地区限制,并且国家/地区限制可以正常工作。

但现在的重点是,我希望它仅在所选城市的输入字段中自动完成城镇名称,因此请在这方面提供一些帮助。

以下是我在这方面使用的代码。

<script type="text/javascript">

function findPropertyLocation(){

    var options = {
      componentRestrictions: {country: "pk"}
     };

    var input = document.getElementById('location-search');
    var autocomplete = new google.maps.places.Autocomplete(input, options);

}

【问题讨论】:

标签: javascript google-maps autocomplete


【解决方案1】:

你不能直接,你可以做的是在搜索中设置Bounds来设置边界,

了解更多关于Bounds,你会找到方法:

https://developers.google.com/maps/documentation/javascript/places-autocomplete#set_search_area

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-28
    • 2016-08-05
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 2020-05-21
    • 2018-04-25
    • 2018-12-08
    相关资源
    最近更新 更多