aboutToAppear(): void {
this.callLocationStart()
this.callDevice()
let target: mapCommon.LatLng = {
latitude: this.latitude,
longitude: this.longitude
};
let cameraPosition: mapCommon.CameraPosition = {
target: target,
zoom: 15
};
this.mapOptions = {
position: cameraPosition
};
this.callback = async (err, mapController) => {
if (!err) {
this.mapController = mapController;
let markerOptions: mapCommon.MarkerOptions = {
position: {
latitude: this.latitude,
longitude: this.longitude
}
};
await this.mapController?.addMarker(markerOptions);
}
};
}
@Builder buildContentView() {
Column() {
this.Title()
MapComponent({ mapOptions: this.mapOptions, mapCallback: this.callback })
.width('100%')
.height('100%')
}
.width('100%')
.height('100%')
}
需要开通地图服务,相关文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/appgallery-connect-0000001751989088