我按照以下步骤初始化google place api:
<script
type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&types=cities"
></script>
并且在我的代码中,我按如下所示引导服务:
const autocomplete = new window.google.maps.places.AutocompleteService();
autocomplete.getPlacePredictions({ input }, predictions => {
console.log(predictions);
});
autocomplete.getPlacePredictions('London');
我希望查询仅返回与该查询匹配的一组城市,但它返回基于伦敦的地址列表。
如何使它只返回与该查询匹配的城市结果?
types
属性无法添加到Maps API脚本本身。您需要将其添加到AutocompleteService.getPlacePredictions
的请求中,如下所示: