2016-12-24 59 views
-1

我正在開發一個應用程序,我需要在Google API提供的各個位置執行簽入。問題在於API不提供所有註冊地點。我在附近的搜索參數中添加了所有地點類型,但這些地方仍然沒有標記。如果有人知道請幫助。 以下是用於附近搜索的代碼。我添加了很多地方,但仍然沒有得到標記Google 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); 
+3

請發佈相關的代碼和錯誤。 – Spechal

+0

我已添加code @Spechal。抱歉,我昨天無法上傳 –

回答

0

其實我在一些研究後得到了解決方案。谷歌地圖API每個電話提供20個地點,可以返回多達60個地點。我們不需要在params中指定類型,而是需要一次又一次地調用分頁(將被稱爲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(); 
     } 
    } 
} 
相關問題