高端地图导航代码android,ReactNative 调用手机地图(高德、百度)导航 Android(示例代码)...

/***@parampkgName

*@paramparam*/@ReactMethodpublic void openNavMap(String pkgName, String param, finalCallback callback) {if(isBlank(param)) {

ResponseModel responseModel= newResponseModel();

responseModel.setErrmsg("参数为空");

callback.invoke(JsonHelper.toJSONString(responseModel));return;

}try{

JSONObject data= newJSONObject(param);

String originLat= data.get("originLat").toString();

String originLng= data.get("originLng").toString();

String destLat= data.get("destLat").toString();

String destLng= data.get("destLng").toString();if(isBlank(pkgName)) {// http://lbsyun.baidu.com/index.php?title=uri/api/web

String url = "http://api.map.baidu.com/direction?origin=%s,%s&destination=%s,%s&region=%s&mode=driving&output=html&src=%s";//打开网页

Intent intent = newIntent();

intent.setAction("android.intent.action.VIEW");

Uri contentUrl= Uri.parse(String.format(url, originLat, originLng, destLat, destLng, this.getName(),this.getName()));

intent.setData(contentUrl);this.getCurrentActivity().startActivity(intent);return;

}

String tmpName=pkgName.trim();if(tmpName.equals(PACKAGE_NAME_BD_MAP)) {

Intent i1= newIntent();//驾车导航

i1.setData(Uri.parse(String.format("baidumap://map/navi?location=%s,%s", destLat, destLng)));this.getCurrentActivity().startActivity(i1);

}else if(tmpName.equals(PACKAGE_NAME_MINI_MAP)) {// http://lbs.amap.com/api/amap-mobile/guide/android/navigation

StringBuffer scheme = new StringBuffer("androidamap://navi?sourceApplication=").append(this.getName());//if (!TextUtils.isEmpty(poiname)){//stringBuffer.append("&poiname=").append(poiname);//}//dev 必填 是否偏移(0:lat 和 lon 是已经加密后的,不需要国测加密; 1:需要国测加密)//style 必填 导航方式(0 速度快; 1 费用少; 2 路程短; 3 不走高速;4 躲避拥堵;5//不走高速且避免收费;6 不走高速且躲避拥堵;7 躲避收费和拥堵;8 不走高速躲避收费和拥堵))

scheme.append("&lat=").append(destLat).append("&lon=").append(destLng).append("&dev=").append(0)

.append("&style=").append(0);

Intent intent= new Intent("android.intent.action.VIEW", Uri.parse(scheme.toString()));

intent.setPackage("com.autonavi.minimap");this.getCurrentActivity().startActivity(intent);

}

}catch(JSONException e) {

e.printStackTrace();

ResponseModel responseModel= newResponseModel();

responseModel.setErrmsg("数据解析错误");

callback.invoke(JsonHelper.toJSONString(responseModel));

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值