/***@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®ion=%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));
}
}