Google Places API自动完成不显示结果

问题描述 投票:1回答:1

在我的React应用中,我使用了Google Places API自动完成功能。我正在使用Google Places API自动完成,这样用户就可以输入他们的位置,他们的citystatecountry信息将被自动填写,但我得到了一个我无法解决的问题。

const autocomplete = new google.maps.places.Autocomplete(input);

当我不指定第二个参数的选项时。一切都很好,但我只想返回用户的城市,州和国家,但当我指定一个类型。自动完成甚至不给我显示结果。

reactjs google-places-api
1个回答
0
投票

我希望在声明你的选项对象时可能有什么问题。但我不看一下你的代码就不能确切的说。

但这是google在他们的google地图Api中提供的例子。我希望这能解决你的问题。

var defaultBounds = new google.maps.LatLngBounds(
  new google.maps.LatLng(-33.8902, 151.1759),
  new google.maps.LatLng(-33.8474, 151.2631));

var input = document.getElementById('searchTextField');
var options = {
  types: ['(cities)'],
  componentRestrictions: {country: 'fr'} // show only results for country France
};

autocomplete = new google.maps.places.Autocomplete(input, options);

更多细节,你可以参考谷歌地图APIhttps:/developers.google.commapsdocumentationjavascriptplaces-autocomplete。

© www.soinside.com 2019 - 2024. All rights reserved.