【问题标题】:Google Places Autocomplete Web Api, get areas of the specific cityGoogle Places Autocomplete Web Api,获取特定城市的区域
【发布时间】:2016-08-15 20:07:23
【问题描述】:

我正在使用 Google Map JavaScript Api。 我想将自动完成搜索结果限制在特定城市的区域和地点。

我试图在 Google 和 Stackoverflow 上找到这个,但找不到答案。

我怎样才能做到这一点?

我正在使用的获取api的链接如下

<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initAutocomplete"
async defer></script>

任何帮助都是宝贵的!

【问题讨论】:

标签: google-maps google-places-api


【解决方案1】:
function initAutocomplete() {
    autocomplete = new google.maps.places.Autocomplete(
            (document.getElementById('cities')),{types: ['establishment']});
    autocomplete.addListener('place_changed', function(){});
}

你可以改变它的类型

要返回的预测类型。支持四种类型:企业的“机构”、地址的“地理编码”、行政区域的“(地区)”和地方的“(城市)”。如果没有指定,则返回所有类型。

https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest

【讨论】:

  • 只允许将搜索限制在国家而不是所选城市的特定区域。
猜你喜欢
  • 2019-01-27
  • 2015-09-03
  • 1970-01-01
  • 2013-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-28
  • 1970-01-01
相关资源
最近更新 更多