注:id:div元素的id,用于构建地图,必须在html写出,否则会报错,诸如Cannot read property ‘gc’ of undefined
transformGoogleToBaidu(id: string, longitude: number, latitude: number) {
const gpsPoint = new BMap.Point(longitude, latitude)
BMap.Convertor.translate(gpsPoint, 0, (point: any) => {
const marker = new BMap.Marker(point)
const bm = new BMap.Map(id)
bm.addControl(new BMap.NavigationControl())
bm.addOverlay(marker)
const label = new BMap.Label('我是百度标注哦', {
offset: new BMap.Size(20, -10),
})
marker.setLabel(label) // 添加百度label
bm.setCenter(point)
console.log('百度坐标', point)
})
}
// 调用转换方法
this.geoLocationService.transformGoogleToBaidu('map_container', 116.386364, 39.911985)