首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法读取未定义的属性‘MAP’:AGM-MAP

无法读取未定义的属性‘MAP’:AGM-MAP
EN

Stack Overflow用户
提问于 2018-07-16 13:00:06
回答 0查看 2K关注 0票数 1

我正在使用谷歌地图来精确定位使用我的应用程序的设备的位置。我正在使用angular 6和集成的谷歌地图使用agm-map库。一切都很好,但是当我试图设置地图的边界,让地图显示每个标记时,我得到了这个错误,

代码语言:javascript
复制
core.js:1598 ERROR TypeError: Cannot read property 'maps' of undefined
    at device-location.view.ts:45
    at SafeSubscriber.schedulerFn [as _next] (core.js:3724)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:253)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:191)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:129)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)
    at EventEmitter.push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next (Subject.js:53)
    at EventEmitter.push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit (core.js:3704)
    at map.js:220
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)

在这里你可以看到我下面的代码,

代码语言:javascript
复制
 ngOnInit() {
      this.devices$.subscribe(data => {
        if (data) {
            this.devices = data;
        }
      });
    }

  ngAfterViewInit() {

    this.agmMap.mapReady.subscribe(map => {
      const bounds: LatLngBounds = new google.maps.LatLngBounds(); // HERE GOOGLE UNDEFINED
      for (const dev of this.devices) {
        bounds.extend(new google.maps.LatLng(dev.latitude, dev.longitude));
      }
      map.fitBounds(bounds);
    });
  }

这是发生错误的代码行,

代码语言:javascript
复制
const bounds: LatLngBounds = new google.maps.LatLngBounds();

有人能帮我解决这个问题吗?谢谢

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51354843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档