gpt4 book ai didi

javascript - 脚本438 : Object doesn't support property or method 'addObject'

转载 作者:行者123 更新时间:2023-11-28 05:46:17 37 4
gpt4 key购买 nike

我有以下代码片段可以将位置添加到 map (此处为 API map )。但在 map.addObject(group); 处,遇到错误,SCRIPT438: Object does not support property or method 'addObject'。我搜索了许多其他解决方案,但没有一个对我有用。这在 Mozilla Firefox 中完美运行,但在 IE 11 中不起作用。可能是什么问题?

locations 是一个数组,仅包含来自 Here Maps Api 的建议位置。

dvList 是一个用于在 map 中绘制点的数组。

function addLocationsToMap(locations) {
$vehPoints = '';
$dvListLength = 0;
var icon = '';
if (locations.length > 0) {
var group = new H.map.Group();
var position, i;
var icon = new H.map.Icon('/Images/Icons/destination1.png');
// Add a marker for each location found
for (i = 0; i < locations.length; i += 1) {
position = {
lat: locations[i].location.displayPosition.latitude,
lng: locations[i].location.displayPosition.longitude
};
marker = new H.map.Marker(position, { icon: icon });
marker.label = locations[i].location.address.label;
group.addObject(marker);
}
marker.addEventListener('tap', function (evt) {
openBubble(evt.target.getPosition(), evt.target.label);
}, false);

if ($dvList == null)
$dvListLength = 0;
else
$dvListLength = $dvList.length;
// Add the locations group to the map
for (var c = 0; c < $dvListLength; c++) {
$lat = $dvList[c].LATITUDE;
$long = $dvList[c].LONGITUDE;
if ($lat != "" && $long != "" && $lat != undefined && $long != undefined && $lat != null && $long != null) {
var radlat1 = Math.PI * parseFloat(position.lat) / 180;
var radlat2 = Math.PI * parseFloat($lat) / 180;
var radlon1 = Math.PI * parseFloat(position.lng) / 180;
var radlon2 = Math.PI * parseFloat($long) / 180;
var theta = parseFloat(position.lng) - parseFloat($long);
var radtheta = Math.PI * theta / 180;
distance = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
distance = Math.acos(distance);
distance = distance * 180 / Math.PI;
distance = distance * 60 * 1.1515;
distance = parseInt(distance * 1.609344);

if (distance <= 100) {
if ($('#radDriver').prop("checked")) {
icon = new H.map.Icon($dvList[c].DVICON);
}
else {
icon = new H.map.Icon($dvList[c].VEHICON);
}
var marker1 = new H.map.Marker({ lat: parseFloat($lat), lng: parseFloat($long) }, { icon: icon });
marker1.setData($dvList[c].TOOLTIP);
group.addObject(marker1);
marker1.addEventListener('tap', function (evt) {
openBubble(evt.target.getPosition(), evt.target.getData());
}, false);
//$vehPoints = $vehPoints + $dvList[c].VEHICLEID + ',';
}
}
}
//end of for loop
map.addObject(group);
map.setViewBounds(group.getBounds());
}
else {
alert('Address not found');
return false;
}

}

如有任何帮助,我们将不胜感激:)

最佳答案

请使用 Maps API for JavaScript 3.1 而不是 3.0。新版本3.1没有这个缺陷。请参阅Migration to 3.1Examples

关于javascript - 脚本438 : Object doesn't support property or method 'addObject' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38498012/

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