/**
* 展示手机上可以用的导航软件
*/
public static void showCanUseMapSoft(final Context context, final String toLa, final String toLo, final String
toName) {
final List<MapInfoModel> list = new ArrayList<MapInfoModel>();
//判断手机上是否安装了百度地图
if (HHAppUtils.isAppInstall(context, "com.baidu.BaiduMap")) {
MapInfoModel model = new MapInfoModel();
model.setMapId("0");
model.setMapName(context.getString(R.string.baidu_map));
list.add(model);
}
//判断手机上是否安装了google地图
if (HHAppUtils.isAppInstall(context, "com.google.android.apps.maps")) {
MapInfoModel model = new MapInfoModel();
model.setMapId("1");
model.setMapName(context.getString(R.string.google_map));
list.add(model);
}
//判断手机上是否安装了高德地图
if (HHAppUtils.isAppInstall(context, "com.autonavi.minimap")) {
MapInfoModel model = new MapInfoModel();
model.setMapId("2");
model.setMapName(context.getString(R.string.auto_navi_ap));
list.add(model);
}
if (HHAppUtils.isAppInstall(context, "com.tencent.map")) {
MapInfoModel model = new MapInfoModel();
model.setMapId("3");
model.setMapName(context.getString(R.string.tencent_map));
list.add(model);
}
if (list.size() == 0) {
HHTipUtils.getInstance().showToast(context, R.string.no_map_can_use);
return;
}
ShowPopupWindow showPopupWindow = new ShowPopupWindow(context, list, new BaseOnItemClickListener() {
@Override
public void onItemClicked(int position) {
switch (list.get(position).getMapId()) {
case "0"://百度地图
try {
Intent intent = new Intent();
// intent.setData(Uri.parse("baidumap://map/direction?origin=name:我的位置|latlng:" + la + "," +
// lo +
// "&destination=" + toLa // 终点纬度
// + "," + toLo// 终点经度
// + "&mode=transit&sy=0&index=0&target=1"));
// intent.setPackage("com.baidu.BaiduMap");
intent.setData(Uri.parse("baidumap://map/direction?destination=latlng:"
+ toLa + ","
+ toLo + "|name:" + toName + // 终点
"&mode=driving" + // 导航路线方式
"&src=" + getPackageName()));
context.startActivity(intent); // 启动调用
} catch (Exception e) {
e.printStackTrace();
}
break;
case "1"://google地图
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://ditu" +
".google" +
".cn/maps?hl=zh&mrt=loc&q=" + toLa + "," + toLo + "(" + toName + ")"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
break;
case "2"://高德地图
try {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse
("androidamap://route?sourceApplication=华信" + "&dlat=" + toLa //终点的经度
+ "&dlon=" + toLo//终点的纬度
+ "&dname=" + toName + "&dev=0" + "&t=1"));
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
break;
case "3"://腾讯地图
try {
StringBuffer stringBuffer = new StringBuffer("qqmap://map/routeplan?type=drive")
.append("&tocoord=").append("37.5154436343").append(",").append("97.3894294758").append("&to=" + toName);
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse
(stringBuffer.toString()));
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
break;
default:
break;
}
}
});
showPopupWindow.showAtLocation(((Activity) context).getWindow().getDecorView(), Gravity.BOTTOM | Gravity
.CENTER_HORIZONTAL, 0, 0);
}