gpt4 book ai didi

javascript - Google map (ngmap 指令)- 未捕获的 TypeError : Cannot read property 'x' of undefined

转载 作者:行者123 更新时间:2023-11-28 06:40:27 25 4
gpt4 key购买 nike

我知道还有其他类似的问题,但这特定于我使用 ngmap 的实现在 MEAN.js 应用程序中。

一切看起来都在按其应有的方式运行,但是..

当页面加载时,我收到此错误两次:

Uncaught TypeError: Cannot read property 'x' of undefined common.js:210

这是错误跟踪:

google maps error

这是我的 HTML:

<div class="row">
<div class="col-md-12">
<ng-map>
<marker data-ng-repeat="device in panelController.model.projects.focused.devices"
position="{{[device.location.lat, device.location.lng]}}"
title="{{device.name}}"
animation="none"
draggable="false"
visible="true"
icon="modules/core/img/dashboard/marker.png">
</marker>
</ng-map>
</div>
</div>

以及相关的 Controller 代码:

self.completeProjectLoad = function(project) {

/* ======= New functionality to set bound box around markers ======= */
function getLocations() {
var locations = [];

for (var i=0; i < project.devices.length; i++) {
locations[i] = [project.devices[i].location.lat, project.devices[i].location.lng];
}

return locations;
}

var locatedDevices = getLocations();


var bounds = new google.maps.LatLngBounds();

// create bounds around all located devices
for (var i=0; i < locatedDevices.length; i++) {
// get the latitude and longitude in the google maps expected format
var latlng = new google.maps.LatLng(locatedDevices[i][0], locatedDevices[i][1]);
//extend the bounds to contain each device
bounds.extend(latlng)
}

// self.mapCenter = bounds.getCenter;

/* ====== End of new functionality ======= */

// Set the bounds of map to include all devices
NgMap.getMap().then(function(map) {
map.setCenter(bounds.getCenter());
map.fitBounds(bounds);
})

};

所有这些共同创造了这个:

enter image description here

正如我所说,事情似乎运行良好,但我怀疑这是一个错误,以后会困扰我。

感谢任何帮助或想法。提前致谢

最佳答案

我不使用 ngmap,但我有完全相同的错误消息:

Uncaught TypeError: Cannot read property 'x' of undefined common.js:179

当我没有定义 centerzoom 选项时,就会发生这种情况。我通过将这些选项添加到 map 初始化来修复。

# this is coffeescript
map = new google.maps.Map(
document.getElementById('map-search')
center: new google.maps.LatLng(42, -71)
zoom: 10
)

关于javascript - Google map (ngmap 指令)- 未捕获的 TypeError : Cannot read property 'x' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33872468/

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