Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图(ngmap指令)-未捕获类型错误:无法读取属性';x';未定义的_Javascript_Google Maps_Google Maps Api 3_Mean Stack - Fatal编程技术网

Javascript 谷歌地图(ngmap指令)-未捕获类型错误:无法读取属性';x';未定义的

Javascript 谷歌地图(ngmap指令)-未捕获类型错误:无法读取属性';x';未定义的,javascript,google-maps,google-maps-api-3,mean-stack,Javascript,Google Maps,Google Maps Api 3,Mean Stack,我知道还有其他类似的问题,但这是特定于我在MEAN.js应用程序中使用的实现的 一切看起来都正常,但 当页面加载时,我两次出现此错误: Uncaught TypeError: Cannot read property 'x' of undefined common.js:210 这是错误跟踪: 这是我的HTML: <div class="row"> <div class="col-md-12"> <ng-map>

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

一切看起来都正常,但

当页面加载时,我两次出现此错误:

Uncaught TypeError: Cannot read property 'x' of undefined common.js:210
这是错误跟踪:

这是我的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>

以及相关的控制器代码:

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);
      })

        };
self.completeProjectLoad=功能(项目){
/*======在标记周围设置绑定框的新功能=======*/
函数getLocations(){
var位置=[];
对于(var i=0;i
所有这些结合在一起形成了:

正如我所说,事情似乎进展顺利,但我怀疑这是一个以后会困扰我的错误


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

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

未捕获的TypeError:无法读取未定义的common.js:179的属性“x”

这是在我没有定义
center
zoom
选项时发生的。我通过将这些选项添加到映射初始化中进行了修复

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

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

未捕获的TypeError:无法读取未定义的common.js:179的属性“x”

这是在我没有定义
center
zoom
选项时发生的。我通过将这些选项添加到映射初始化中进行了修复

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

什么是
project.devices
?他们是谷歌拉特林对象或标记等?如果是这样的话,您可能应该使用像
getPosition()
lat()
/
lng()
这样的函数来获取lat&lng值,而不是依赖于lat和lng属性。谢谢,但我看不出这有什么帮助?project.devices只是具有lat和long属性的对象,我在第二个for循环中将其转换为Google LatLng对象,以便设置边界。你能解释一下为什么会解决这个问题吗?好的,如果它们不是谷歌地图对象,那么它就不适用了。什么是
project.devices
a数组?他们是谷歌拉特林对象或标记等?如果是这样的话,您可能应该使用像
getPosition()
lat()
/
lng()
这样的函数来获取lat&lng值,而不是依赖于lat和lng属性。谢谢,但我看不出这有什么帮助?project.devices只是具有lat和long属性的对象,我在第二个for循环中将其转换为Google LatLng对象,以便设置边界。你能解释一下为什么这会解决这个问题吗?好吧,如果它们不是谷歌地图对象,那么它就不适用了。