angualr 使用angular2-baidu-map的问题

发布于 2022-09-11 18:00:26 字数 1572 浏览 17 评论 0

clipboard.png
add.module.ts

import { AddComponent } from './add.component';

import { ComponentsModule } from '@/components/components.module';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';


@NgModule({
  declarations: [
    AddComponent,
  ],
  imports: [
    BaiduMapModule.forRoot({ ak: '12y44u6KQ1bEf5aMNKzoEhHnfpM6vFji' }),
    ComponentsModule,
    RouterModule.forChild([{
      path: '', component: AddComponent,
    }]),
  ],
})
export class AddModule { }

add.component.ts

import {
  BMapInstance, MapOptions, Point, MarkerOptions, NavigationControlOptions, ControlAnchor,
  NavigationControlType, OverviewMapControlOptions, ScaleControlOptions,
} from 'angular2-baidu-map';


  getLocation() {
    console.log(window.BMap)
    let geolocation = new window.BMap.Geolocation();
    geolocation.getCurrentPosition(function(r) {
      if (this.getStatus() == 'BMAP_STATUS_SUCCESS') {
        let mk = new window.BMap.Marker(r.point);
        this.bmap.addOverlay(mk);
        this.bmap.panTo(r.point);
        alert('您的位置:' + r.point.lng + ',' + r.point.lat);
      }
      else {
        alert('failed' + this.getStatus());
      }
    }, { enableHighAccuracy: true })
  }

  ngOnInit() {
    this.getLocation();
    }

现在是想初始获取浏览器当前定位
但是报错
clipboard.png
打印的window.BMap也是undefined
请问这里应该怎么引入 和实例化呢

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不乱于心 2022-09-18 18:00:26

window.BMap是什么鬼

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文