有没有办法限制Google商家信息自动填充功能搜索城市的街道?

Il *_*sso 11 jquery google-maps-api-3 google-places-api

使用Google地方信息时,我可以将搜索范围限制在城市的街道Autocomplete吗?

Sea*_*key 6

您可以设置Autocompletegeocode用作类型的选项,这将限制返回到地址的结果:

var input = document.getElementById( 'searchTextField' );
var options = {
  bounds: yourBounds,
  types: ['geocode']
};

autocomplete = new google.maps.places.Autocomplete( input, options );
Run Code Online (Sandbox Code Playgroud)

有没有办法限制的结果,只是街道,但是这将在很大程度上实现你想要的.如果你设置yourBounds正确,可能只限于一个城市的区域,它会让你尽可能接近.

更新回复评论:

如果要从输入城市开始,可以将地图的边界绑定到Autocomplete边界,当地图在以下位置被选中时,地图将自动设置其视口Autocomplete:

var options = {
  bounds: yourBounds,
  types: ['(cities)']
};
autocomplete =
    new google.maps.places.Autocomplete( input, options );
// This will bind the map's bounds to the Autocomplete's bounds:
autocomplete.bindTo('bounds', map);
Run Code Online (Sandbox Code Playgroud)

然后,您可以更新Autocomplete类型,类似于上面的类型,以使其返回地址:

autocomplete.setTypes( [ "geocode" ] );
Run Code Online (Sandbox Code Playgroud)

从那里,您可以阅读Places Library API文档.