angualr 使用angular2-baidu-map的问题

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
请问这里应该怎么引入 和实例化呢

阅读 2.8k
1 个回答

window.BMap是什么鬼

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进