gpt4 book ai didi

javascript - 我如何使用javascript变量为附近的地方分配类型

转载 作者:行者123 更新时间:2023-11-30 06:37:49 24 4
gpt4 key购买 nike

编辑:问题已解决我正在尝试使用这样的变量分配类型

    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 文档,您调用的函数期望请求对象中的类型是:

An array containing one or more of the supported types listed in the Google Places API: Supported Place Types list.

所以像这样使用检查对象

var request = {
location: latlng,
radius: '50000',
types: check
};

更多信息 here

关于javascript - 我如何使用javascript变量为附近的地方分配类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13440866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com