Google Places Auto-Complete

僤鯓⒐⒋嵵緔 提交于 2020-01-10 05:00:09

问题


The input box is initialized properly but it is not generating any suggestions. Can any one point out what I am doing wrong? Here is the code.

Update

I have investigated the issue. The problem is in the line:

types: ['(cities)', '(regions)']

when I specify only one type types: ['(cities)'] no matter region or cities it works. But two types are not working together. Although the documentation clearly says that types are Array of strings and valid values are 'establishment', 'geocode', '(regions)' and '(cities)'


回答1:


As mentioned in the documentation:

"types, which can either specify one of two explicit types or one of two type collections."

This means that the types array only supports one parameter.

If you think it would be a useful feature to support more than one parameter or a mixture of explicit types and collections, please file a Places API - Feature Request.




回答2:


As Chris mentioned, there is currently no way to get results for multiple place types. However, you can call the API twice with different place types and populate a map (or whatever you're building) with both types. For example:

var request1 = {
  location: event.latLng,
  radius: 8047,
  types: ['cafe'],
};
var request2 = {
  location: event.latLng,
  radius: 8047,
  types: ['library'],
};



回答3:


There are no results of type (cities)' or '(regions)'. If I change the types array to ['establishment'], I get results.

Working example

If you use only one type, it works:

Example



来源:https://stackoverflow.com/questions/13233196/google-places-auto-complete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!