HarmonyOS 鸿蒙Next 高德地图集成
HarmonyOS 鸿蒙Next 高德地图集成
高德地图集成
在集成高德地图的过程中发现,如果按照它文档里的方法,在aboutToAppear执行设置,运行后地图显示异常,但是如果根据高德的demo项目里的方法,把处理操作整到一个类里,同样在aboutToAppear里调用,显示正常,想不明白这咋回事啊!
demo里的封装如下
export class MapMyLocationController2 implements IMapController {
private mapView?: MapView;
private aMap?: AMap;
private aId: number;
constructor() {
this.aId = IdGenerator.instance().generateId();
MapsInitializer.setDebugMode(true);
MapsInitializer.setApiKey(ContentKey.GaoDeMapKey);
}
getMapView(): MapView | undefined {
return this.mapView;
}
getAMap(): AMap | undefined {
return this.aMap;
}
getId(): number {
return this.aId;
}
show(): void {
MapViewManager.getInstance().getMapView((mapview?: MapView) => {
if (!mapview) {
return;
}
this.mapView = mapview;
this.mapView.onCreate();
this.mapView.getMapAsync((map) => {
this.aMap = map;
showLog('map3d' + 'get map ' + this.aMap?.getCameraPosition()?.zoom);
// let uisettings = this.aMap?.getUiSettings();
// let projection = this.aMap?.getProjection();
// let approvalNumber = this.aMap?.getMapContentApprovalNumber();
// let satelliteImageApprovalNumber = this.aMap?.getSatelliteImageApprovalNumber();
this.aMap?.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(116.29912099501364,39.82496648836822), 14));
let locationStyle: MyLocationStyle = new MyLocationStyle();
locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW);
// locationStyle.anchor(1,1)
this.aMap?.setMyLocationStyle(locationStyle);
this.aMap?.setLocationSource(this);
this.aMap?.setMyLocationEnabled(true);
// add Marker
let options: MarkerOptions = new MarkerOptions();
options.setPosition(new LatLng(39.82496648836822,116.29952099501364));
options.setAnchor(0.5, 1.0);
// options.setPosition(new LatLng(40.02380181476392, 116.43124537956452));
options.setTitle('Anno');
options.setSnippet('111111111')
// options.setVisible(false);
// options.setIcon(new BitmapDescriptor($rawfile('location_map_gps_locked.png'), 'location_map_gps_locked', 100, 100));
let marker = this.aMap?.addMarker(options);
if (marker) {
marker.showInfoWindow();
// this.aMap.removeOverlay(marker.getId());
// marker.setVisible(true);
marker.setIcon(new BitmapDescriptor($rawfile('marker.png'), 'marker', 100, 100));
// marker.setIcon(new BitmapDescriptor($r('app.media.marker_nei'), 'marker'));
// marker.setPosition(new LatLng(40.02380181476392, 116.43124537956452));
marker.setDraggable(true);
}
})
});
}
hide(): void {
if (this.mapView) {
this.mapView.onDestroy();
}
}
activate(listener: OnLocationChangedListener): void {
let location: geoLocationManager.Location = {
accuracy: 1000,
altitude: 0,
direction: 0,
latitude: 39.824967347208585,
longitude: 116.29911418891147,
speed: 0,
timeSinceBoot: 123587419434256,
timeStamp: 0
};
try {
listener.onLocationChanged(location);
} catch (e) {
console.info((e as BusinessError).message);
}
// const options: AMapLocationOption = {
// priority: geoLocationManager.LocationRequestPriority.FIRST_FIX,
// scenario: geoLocationManager.LocationRequestScenario.UNSET,
// maxAccuracy: 0,
// singleLocationTimeout: 3000,
// allowsBackgroundLocationUpdates: false,
// locatingWithReGeocode: false,
// reGeocodeLanguage: AMapLocationReGeocodeLanguage.Chinese,
// isOffset: false
// }
// requestLoction(getContext(this), has => {
// showLog("权限申请:" + (has ? '成功' : '拒绝或报错'))
// if (has) {
// // getLoction(getContext(this))
// let locationManger = new AMapLocationManagerImpl(getContext(this));
// locationManger?.setLocationOption(AMapLocationType.Single, options)
// locationManger?.setLocationListener(AMapLocationType.Single, {
// onLocationChanged: (location) => {
// showLog('定位成功')
//
// // AppStorage.setAndLink('loc_lat_lng', getLocDef())
// // .set(new LatLng(location.latitude, location.longitude))
// // let location: geoLocationManager.Location = {
// // accuracy: 1000,
// // altitude: 0,
// // direction: 0,
// // latitude: 39.824967347208585,
// // longitude: 116.29911418891147,
// // speed: 0,
// // timeSinceBoot: 123587419434256,
// // timeStamp: 0
// // };
// try {
// listener.onLocationChanged(location);
// } catch (e) {
// console.info((e as BusinessError).message);
// }
// // locationManger?.stopUpdatingLocation()
// }, onLocationError: (error) => {
// showLog('定位失败')
// AppStorage.setAndLink('loc_lat_lng', getLocDef())
// .set(getLocDef())
// // locationManger?.stopUpdatingLocation()
// }
// })
// locationManger?.requestSingleLocation()
// }
// })
}
deactivate() {
}
}
1 回复
关于HarmonyOS 鸿蒙Next 高德地图集成的问题,以下是一些专业解答:
高德地图已成功集成到HarmonyOS 鸿蒙Next系统中,实现了基础功能以及搜索、路线规划、导航等核心功能的适配。此外,高德地图还针对不同屏幕尺寸的设备进行了优化,包括折叠屏和全面屏,确保在不同设备上都能提供流畅的用户体验。
在HarmonyOS 鸿蒙Next上,高德地图充分利用了鸿蒙系统的分布式软总线技术,实现了跨设备接续导航的功能。用户可以在手机上开启导航,然后一键切换到车机或其他鸿蒙设备上,实现无缝流转和高效协同。
高德地图还接入了HarmonyOS的意图框架和小艺智能体,使用户可以通过语音指令直接触发导航或打车功能,省去了繁琐的操作步骤。同时,高德地图还利用了鸿蒙开发套件中的超分超帧技术、毕昇编译器等优化工具,提升了应用性能和流畅性。
如果在使用过程中遇到任何问题,建议查阅HarmonyOS和高德地图的官方文档或联系官网客服进行解决。官网地址是:https://www.itying.com/category-93-b0.html。