一.百度导航调用方法:
public static void goBaidu(Context context, LatLng start, LatLng endPt) {
Intent intent = null;
if (AppUtils.isInstallApp(BAIDU_PACKAGE_NAME)) {
try {
String pareUrl = "baidumap://map/direction?region=" +
"&origin=" + start.latitude + "," + start.longitude +
"&destination=" + endPt.latitude + "," + endPt.longitude + "&mode=walking";
intent = Intent.getIntent(pareUrl);
context.startActivity(intent);
} catch (URISyntaxException e) {
e.printStackTrace();
}
} else {
ToastUtil.show("请先安装百度地图");
}
}
更多请查看百度官方文档走,去看看
二.高德地图导航调用方式
public static void goGd(Context context, LatLng endPt) {
if (AppUtils.isInstallApp(GD_PACKAGE_NAME)) {
Intent intent = new Intent("android.intent.action.VIEW",
android.net.Uri.parse("androidamap://route?sourceApplication=" + AppUtils.getAppName() + "&poiname=&dlat=" + endPt.latitude
+ "&dlon=" + endPt.longitude + "&dev=0&t=0&style=2"));
context.startActivity(intent);
} else {
ToastUtil.show("请先安装高德地图");
}
}
高德地图更多信息请看官方文档走你
代码中需要的其他方法:
public static final String GD_PACKAGE_NAME = "com.autonavi.minimap";
public static final String BAIDU_PACKAGE_NAME = "com.baidu.BaiduMap";
/**
* 判断App是否安装
*
* @param packageName 包名
* @return {@code true}: 已安装<br>{@code false}: 未安装
*/
public static boolean isInstallApp(String packageName) {
return !isSpace(packageName) && IntentUtils.getLaunchAppIntent(packageName) != null;
}
private static boolean isSpace(String s) {
if (s == null) return true;
for (int i = 0, len = s.length(); i < len; ++i) {
if (!Character.isWhitespace(s.charAt(i))) {
return false;
}
}
return true;
}
/**
* 获取打开App的意图
*
* @param packageName 包名
* @return intent
*/
public static Intent getLaunchAppIntent(String packageName) {
return AppContext.appContext.getPackageManager().getLaunchIntentForPackage(packageName);
}
以上就是百度和高德第三方调起导航的方法。
愿每一个程序员都别遇到内置导航的需求!!!
网友评论