![](/img/trans.png)
[英]How can I assign a number for a variable by using getElementById method in JavaScript
[英]how can i assign types for nearby place using javascript variable
編輯:問題解決了我正在嘗試使用這樣的變量分配類型
check = [];
if($("#transport").attr("checked"))
check.push('airport','bus_station','train_station','taxi_stand','travel_agency');
if($("#bars").attr("checked"))
check.push('bar','restaurant');
if($("#tourist").attr("checked"))
check.push('art_gallery','campground','museum','aquarium','zoo','library','amusement_park','park');
if($("#shopping").attr("checked"))
check.push('shopping_mall','shoe_store','jewelry_store','grocery_or_supermarket','furniture_store','electronics_store','clothing_store','book_store');
var tmp_types = "";
for(i=0;i<1;i++)
{
tmp_types += '"'+check[i]+'"';
}
var request = {
location: latlng,
radius: '50000',
types: [ tmp_types ]
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
但是它不起作用...有人可以幫我嗎...謝謝
解決方案:只需使用check代替tmp_types並刪除方括號..像這樣的類型:check ..感謝Bruno
您的for循環從0退出,因為您的條件是i < 1
for( var i=0, len = check.length; i < len; i++ ) {
// your code here
}
此外,根據API文檔,您正在調用的函數期望請求對象中的類型為:
一個數組,其中包含Google Places API:支持的位置類型列表中列出的一種或多種支持的類型。
所以像這樣使用檢查對象
var request = {
location: latlng,
radius: '50000',
types: check
};
更多信息在這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.