高德地图导航和百度地图导航,传入所需参数可直接使用
public class MapUtils {
/**
* 调起导航
* @param context
* @param address 目的地地址
* @param city 目的地所在城市
* @param lat 目的地纬度
* @param lon 目的地经度
*/
public static void invokingBD(Context context,String address,String city,String lat,String lon){
if(isInstallByread("com.baidu.BaiduMap")){
Intent intent =null;
try {
String uri ="intent://map/direction?origin=latlng:0,0|name:我的位置&destination="
+ address +"&mode=drivingion=" + city
+"&referer=Autohome|GasStation#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end";
intent =Intent.getIntent(uri);
}catch (URISyntaxException e) {
e.printStackTrace();
}
context.startActivity(intent); //启动调用
}else if (isInstallByread("com.autonavi.minimap")){
//https://lbs.amap.com/api/amap-mobile/guide/android/route
String uri ="";
//直接导航
uri ="androidamap://navi?sourceApplication=神农识&lat="+ lat+"&lon="+lon+"&dev=0"+"&style=0";
//规划路线
uri ="amapuri://route/plan/?sid=&slat=&slon=&sname=&did=&" +"dlat=" +lat +"&dlon=" +lon + "&dname="+address+"&dev=0&t=0";
Intent intent =new Intent("android.intent.action.VIEW",android.net.Uri.parse(uri));
intent.setPackage("com.autonavi.minimap");
intent.addCategory("android.intent.category.DEFAULT");
// intent.setData(Uri.parse("androidamap://poi?sourceApplication=softname&keywords="+address));
context.startActivity(intent);
Log.e("GasStation", "高德地图客户端已经安装");
}else {
Toast.makeText(context, "您尚未安装地图客户端", Toast.LENGTH_SHORT).show();
//跳转到应用商店去下载高德地图app
Uri uri =Uri.parse("market://details?id=com.autonavi.minimap");
Intent intent =new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
/**
* 判断是否安装目标应用
* @param packageName 目标应用安装后的包名
* @return 是否已安装目标应用
*/
private static boolean isInstallByread(String packageName) {
return new File("/data/data/" + packageName).exists();
}
}
网友评论