我正在开发一款应用,我需要在Google API提供的各个地方办理登机手续。问题是API没有提供所有注册的地方。我在附近的搜索参数中添加了所有地点类型,但这些地方仍然没有标记。如果有人知道请帮忙。 以下是附近搜索的代码。我添加了很多地方但仍未获得标记
function loadNearByPlaces(latLng) {
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: latLng,
radius: 5000,
// type: ['any']
types: ['airport', 'amusement_park', 'aquarium', 'art_gallery', 'bar', 'book_store', 'bowling_alley', 'cafe', 'casino', 'church',
'clothing_store', 'department_store', 'gym', 'hospital', 'library', 'lodging', 'museum', 'night_club', 'park', 'restaurant', 'rv_park',
'school', 'shopping_mall', 'stadium', 'university', 'zoo', //my own types,
'bank', 'bakery', 'bus_station', 'car_wash', 'city_hall', 'post_office', 'shopping_mall', 'subway_station', 'university',
'furniture_store', 'fire_station', 'embassy', 'pharmacy', 'convenience_store', 'shoe_store', 'spa', 'train_station', 'transit_station',
'police', 'doctor', 'courthouse', 'roofing_contractor', 'hair_care', 'local_government_office', 'jewelry_store', 'lawyer', 'locksmith',
'accounting', 'cemetery', 'car_dealer', 'florist', 'home_goods_store', 'store', 'synagogue', 'laundry', 'insurance_agency', 'point_of_interest',
'post_box', 'colloquial_area', 'food', 'general_contractor', 'intersection', 'locality', 'neighborhood', 'subpremise', 'place_of_worship',
'political', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'administrative_area_level_4',
'administrative_area_level_5', 'colloquial_area', 'country', 'establishment', 'finance', 'floor', 'food', 'geocode', 'health', 'intersection', 'locality', 'natural_feature',
'neighborhood', 'place_of_worship', 'political', 'point_of_interest', 'post_box', 'postal_code', 'postal_code_prefix', 'postal_code_suffix', 'postal_town',
'premise', 'room', 'route', 'street_address', 'street_number', 'sublocality', 'sublocality_level_4', 'sublocality_level_5', 'sublocality_level_3',
'sublocality_level_2', 'sublocality_level_1', 'subpremise', 'Indiana Convention Center'
]
}, callback);
答案 0 :(得分:1)
实际上我经过一些研究后得到了解决方案。 Google maps api每次通话提供20个位置,最多可返回60个位置。我们不需要在参数中指定类型,而是我们必须一次又一次地调用分页(它将被调用3次)每次调用将导致添加20个标记。我将代码修改为
function loadNearByPlaces(latLng) {
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: latLng,
radius: 100
}, callback);
}
function callback(results, status, pagination) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
// places.push(results[i])
}
if (pagination.hasNextPage) {
pagination.nextPage();
}
}
}