我正在为我们的网站制作一个搜索插件,允许用户使用Google Places API搜索任何位置,并列出我们的公寓及其到该位置的距离。
为了限制对用户的搜索,我在方法:getPlacePredictions()
中添加了一些可能的限制,可以在Google Places API对象google.maps.places.AutocompleteService()
中使用。
国家:仅德国
首选搜索区域: northrine -westfalia(德国一个地区)
function pacGetSuggestions(searchString) {
// set autocomplete options
var pacOptions = {
input : searchString,
componentRestrictions : {country: 'de'}, // restrict results to germany
bounds : pacDefaultBounds, // add search area
};
// get suggestions
PAC.getPlacePredictions(pacOptions, pacDrawSuggestions);
}
到目前为止,这个工作正常!
我的问题:
如何限制特定位置类型的结果?有办法吗?
例子:
我不希望用户能够搜索酒店/旅馆等,因为这将是对我们的直接竞争。
如果用户在"Hill-Street"或"HillyBilly Pizza Place"中输入"hill",则不应该显示"Hilton Hotels, Somethingstreet…"。
这可能吗?
支持的类型如下:https://developers.google.com/places/documentation/supported_types
您也可以按国家筛选:components -一组您希望限制结果的位置。目前,您可以使用组件按国家进行过滤。国家必须以两个字符的方式传递,ISO 3166-1 Alpha-2兼容的国家代码。例如:components=country:fr会将您的搜索结果限制在法国境内。
https://developers.google.com/places/documentation/autocomplete