Google Places API: 如何使用多种类型?
Google Places API: How to use multiple types?
我需要一个 POI API returns 评级、照片、opening/closing 次等,我认为 Google 个地点 API 似乎可以做什么我想要,但我在过滤时遇到了一些麻烦:我想使用具有多种类型的自动完成功能进行过滤。
这是我的资料:
var map;
var selectAttractionAutocomplete;
var selectCityAutocompleteOptions = {
types: ['(cities)']
};
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(-33.8665433, 151.1956316),
zoom: 15
});
var inputsearchedCity = document.getElementById('input-searched-city');
selectCityAutocomplete = new google.maps.places.Autocomplete(inputsearchedCity, selectCityAutocompleteOptions);
selectCityAutocomplete.bindTo('bounds', map);
google.maps.event.addListener(selectCityAutocomplete, 'place_changed', function () {
console.log(selectCityAutocomplete.getPlace());
});
如何使用多种类型?
我试过竖线、逗号、方括号……都没有用:
var selectCityAutocompleteOptions = {
types: ['cities|point_of_interest']
};
根据 Google Documentation,point_of_interest
属于类型 2,地点搜索的类型过滤器或添加地点时的类型 属性 不支持这种类型。
var request = {
bounds: map.getBounds(),
types: ['bar','park']
//keyword: 'best view'
};
最近遇到了这个。答案在这里Google Places Auto-Complete
types, which can either specify one of two explicit types or one of two type collections.
如果您在查询字符串中使用,请使用 |分隔器。请记住,目前只有 'geocode|establishment' 作为集合类型有效,这与未指定任何组合类型相同。
参见:
https://developers.google.com/places/web-service/autocomplete#place_types
You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types.
这个问题在 this thread 中得到了部分回答。
首先,不支持"cities"的地方类型。您可以找到支持的地点类型列表 here。
无法同时使用多种类型。但是,您可以调用 API 两次以获得相似的结果。例如:
var selectCityAutocompleteOptions1 = {
types: ['zoo']
};
var selectCityAutocompleteOptions2 = {
types: ['museum']
};
不过,根据您的描述,您似乎想要所有兴趣点结果,而不是按类型过滤。在这种情况下,您可能想改用 Find Place Requests Place Search。
我需要一个 POI API returns 评级、照片、opening/closing 次等,我认为 Google 个地点 API 似乎可以做什么我想要,但我在过滤时遇到了一些麻烦:我想使用具有多种类型的自动完成功能进行过滤。
这是我的资料:
var map;
var selectAttractionAutocomplete;
var selectCityAutocompleteOptions = {
types: ['(cities)']
};
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(-33.8665433, 151.1956316),
zoom: 15
});
var inputsearchedCity = document.getElementById('input-searched-city');
selectCityAutocomplete = new google.maps.places.Autocomplete(inputsearchedCity, selectCityAutocompleteOptions);
selectCityAutocomplete.bindTo('bounds', map);
google.maps.event.addListener(selectCityAutocomplete, 'place_changed', function () {
console.log(selectCityAutocomplete.getPlace());
});
如何使用多种类型?
我试过竖线、逗号、方括号……都没有用:
var selectCityAutocompleteOptions = {
types: ['cities|point_of_interest']
};
根据 Google Documentation,point_of_interest
属于类型 2,地点搜索的类型过滤器或添加地点时的类型 属性 不支持这种类型。
var request = {
bounds: map.getBounds(),
types: ['bar','park']
//keyword: 'best view'
};
最近遇到了这个。答案在这里Google Places Auto-Complete
types, which can either specify one of two explicit types or one of two type collections.
如果您在查询字符串中使用,请使用 |分隔器。请记住,目前只有 'geocode|establishment' 作为集合类型有效,这与未指定任何组合类型相同。
参见: https://developers.google.com/places/web-service/autocomplete#place_types
You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types.
这个问题在 this thread 中得到了部分回答。
首先,不支持"cities"的地方类型。您可以找到支持的地点类型列表 here。
无法同时使用多种类型。但是,您可以调用 API 两次以获得相似的结果。例如:
var selectCityAutocompleteOptions1 = {
types: ['zoo']
};
var selectCityAutocompleteOptions2 = {
types: ['museum']
};
不过,根据您的描述,您似乎想要所有兴趣点结果,而不是按类型过滤。在这种情况下,您可能想改用 Find Place Requests Place Search。