import {NativeModules, NativeEventEmitter} from 'react-native'; const {RNAmapNavi} = NativeModules; const AmapEventEmitter = new NativeEventEmitter(RNAmapNavi); const AmapModule = NativeModules.RNAmapNavi; /** * 语音播报模式常量 */ export const VoiceMode = { /** 详细播报 */ DETAILED: 0, /** 简洁播报 */ CONCISE: 1, /** 关闭播报 */ OFF: 2, }; export const AmapNavi = { /** * 开始驾车导航 使用自定义view */ startDrivingNavigationView(startPoi, endPoi, waysList = [], drivingStrategy = 0, drivingDistance = 0) { const startLatitude = Number(startPoi.latitude); const startLongitude = Number(startPoi.longitude); const endLatitude = Number(endPoi.latitude); const endLongitude = Number(endPoi.longitude); if (startLatitude && startLongitude && endLatitude && endLongitude) { if (typeof startLatitude === 'number' && typeof startLongitude === 'number' && typeof endLatitude === 'number' && typeof endLongitude === 'number') { AmapModule.startDrivingNavigationView({ latitude: startLatitude, longitude: startLongitude }, { latitude: endLatitude, longitude: endLongitude }, waysList, drivingStrategy, drivingDistance ); } } }, /** * 算路 */ calculateDriveRouteAsync(startPoi, endPoi, waysList = [], drivingStrategy = 0) { const startLatitude = Number(startPoi.latitude); const startLongitude = Number(startPoi.longitude); const endLatitude = Number(endPoi.latitude); const endLongitude = Number(endPoi.longitude); if (startLatitude && startLongitude && endLatitude && endLongitude) { if (typeof startLatitude === 'number' && typeof startLongitude === 'number' && typeof endLatitude === 'number' && typeof endLongitude === 'number') { return AmapModule.calculateDriveRoute({ latitude: startLatitude, longitude: startLongitude }, { latitude: endLatitude, longitude: endLongitude }, waysList.map(({latitude, longitude}) => ({ latitude: Number(latitude), longitude: Number(longitude) })), drivingStrategy ); } } }, /** * drivingNavigation 驾车导航事件 * -1 步行或者驾车路径规划失败 * 0 导航初始化失败 * 1 启动导航后成功 * 2 算路成功 * 3 当GPS位置有更新 * 4 到达目的地 * -2 退出导航 extra:1退出导航 1退出地图 */ /** * onLocationInformation定位监听事件 */ /** * 监听poi搜索数据 * onPOISearchDone */ /* 驾车算路监听事件 onDriveRouteSearched 回调算路结果 */ addEventListener(event, callback) { if (!event) { return; } return AmapEventEmitter.addListener(event, (data) => { callback(data); }); } }