Commit 0768ead30e6912e7b00444250fd747346a717631

Authored by 张志伟
1 parent 80405b29

新增打开外部高德地图导航

lib/android/src/main/java/cn/feewee/amap3d/modules/SdkModule.kt
1 1 package cn.feewee.amap3d.modules
2 2  
3 3 import com.amap.api.location.AMapLocationClient
  4 +import com.amap.api.maps.AMapException
  5 +import com.amap.api.maps.AMapUtils
4 6 import com.amap.api.maps.MapsInitializer
  7 +import com.amap.api.maps.model.LatLng
  8 +import com.amap.api.maps.model.RoutePara
5 9 import com.facebook.react.bridge.Promise
6 10 import com.facebook.react.bridge.ReactApplicationContext
7 11 import com.facebook.react.bridge.ReactContextBaseJavaModule
... ... @@ -28,4 +32,21 @@ class SdkModule(val context: ReactApplicationContext) : ReactContextBaseJavaModu
28 32 fun getVersion(promise: Promise) {
29 33 promise.resolve(MapsInitializer.getVersion())
30 34 }
  35 +
  36 + @ReactMethod
  37 + fun openAmapNavi(sLat: Double, sLng: Double, eLat: Double, eLng: Double, sName: String?, eName: String?, promise: Promise) {
  38 + try {
  39 + val routePara = RoutePara()
  40 + routePara.startPoint = LatLng(sLat,sLng)
  41 + routePara.endPoint = LatLng(eLat,eLng)
  42 + routePara.startName = sName
  43 + routePara.endName = eName
  44 + AMapUtils.openAMapDrivingRoute(routePara, context)
  45 + promise.resolve(null)
  46 + } catch (ae: AMapException) {
  47 + promise.reject("-2", ae.errorMessage, ae);
  48 + } catch (e:Exception) {
  49 + promise.reject("-1", "未知错误,请重试", e);
  50 + }
  51 + }
31 52 }
... ...
lib/src/sdk.ts
1 1 import { NativeModules, Platform } from "react-native";
2 2 import { AppKey } from "./gen-types";
  3 +import { LatLng } from "./types";
3 4  
4 5 const { AMapSdk } = NativeModules;
5 6  
... ... @@ -10,3 +11,14 @@ export function init(key: AppKey) {
10 11 export function getVersion(): Promise<string> {
11 12 return AMapSdk.getVersion();
12 13 }
  14 +/**
  15 + * 调用手机上的高德地图导航
  16 + * @param start 起始地经纬度
  17 + * @param end 目的地经纬度
  18 + * @param startName 开始地址
  19 + * @param endName 目的地地址
  20 + * @returns
  21 + */
  22 +export function openNavi(start: LatLng, end: LatLng, startName?: string, endName?: string): Promise<null> {
  23 + return AMapSdk.openAmapNavi(start.latitude, start.longitude, end.latitude, end.longitude, startName, endName);
  24 +}
... ...
package.json
1 1 {
2 2 "name": "@cqfw/react-native-amap3d",
3   - "version": "0.1.1",
  3 + "version": "0.1.2",
4 4 "description": "react-native 高德地图组件,支持 Android + iOS",
5 5 "author": "feewee",
6 6 "license": "MIT",
... ...