无法读取未定义的属性"映射":AGM-MAP



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

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)

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

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

这是发生错误的代码行,

const bounds: LatLngBounds = new google.maps.LatLngBounds();

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

谷歌似乎没有初始化,请尝试

declare const google: any;

或者安装谷歌地图打字

npm install @types/google-maps --save-dev

相关内容

  • 没有找到相关文章

最新更新