android打开外部地图导航(百度、高德、腾讯)

1.参考下面的地址:我的调用百度的就是采用这个文章的方法

https://blog.csdn.net/hyyz3293/article/details/76836633


2,我自己采用的方法,如下;

//todo:获取当前自己的位置;
getLocation(new BDLocationListener() {
    @Override
    public void onReceiveLocation(BDLocation location) {
        MLog.d(TAG, location.toString());
        dismissDialog();
        float LatitudeNow = (float) location.getLatitude();
        float LongitudeNow = (float) location.getLongitude();

        if (LatitudeNow > 0 && LongitudeNow > 0) {
            SharedPreferencesTool.setEditor(context, "LatitudeNow", LatitudeNow);
            SharedPreferencesTool.setEditor(context, "LongitudeNow", LongitudeNow);
        }
        MLog.i("LatitudeNow",LatitudeNow+"");
        MLog.i("LongitudeNow",LongitudeNow+"");

    }
});


mMap = new ArrayList<>();
if (isAppInstalled("com.google.android.apps.maps")) {
    mMap.add("谷歌地图");
}
if (isAppInstalled("com.baidu.BaiduMap")) {
    mMap.add("百度地图");
}
if (isAppInstalled("com.autonavi.minimap")) {
    mMap.add("高德地图");
}
if (isAppInstalled("com.tencent.map")) {
    mMap.add("腾讯地图");
}
if (mMap.size() != 0) {
    final String[] maps = new String[mMap.size()];
    for (String s : mMap) {
        Log.e("1111", s);
    }
    for (int i = 0; i < mMap.size(); i++) {
        maps[i] = mMap.get(i);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(ExtWebDetailActivity.this);
                                builder.setTitle("请选择");
                                //设置一个下拉的列表选择项
                                builder.setItems(maps, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {

                                        float latitudeNow = SharedPreferencesTool.getSharedPreferences(ExtWebDetailActivity.this, "LatitudeNow", -1f);
                                        float LongitudeNow = SharedPreferencesTool.getSharedPreferences(ExtWebDetailActivity.this, "LongitudeNow", -1f);

                                        double[] doubles1 = GPSUtil.bd09_To_Gcj02(latitudeNow, LongitudeNow);
                                        double latitudeNow1 = doubles1[0];
                                        double LongitudeNow1 = doubles1[1];


                                        double[] doubles2 = GPSUtil.bd09_To_Gcj02(Float.valueOf(weidu) , Float.valueOf(jingdu));
                                        double latitudeNow2 = doubles2[0];
                                        double LongitudeNow2 = doubles2[1];


                                        if (maps[which].equals("腾讯地图")) {
                                            // 腾讯地图
//                                            Log.e("1111", "打开腾讯地图");
                                            Intent naviIntent = new Intent("android.intent.action.VIEW", android.net.Uri.parse("qqmap://map/routeplan?type=drive&from="+"我的位置"+"&fromcoord="+latitudeNow1+","+LongitudeNow1+"&to=" +"目的地"+ "&tocoord=" + latitudeNow2 + "," + LongitudeNow2+ "&policy=0&referer="+"翠微e生活"));
                                            ExtWebDetailActivity.this.startActivity(naviIntent);
                                        } else if (maps[which].equals("百度地图")) {
                                            try {
                                                //这个方法是没用的
//                                                Intent   intent = Intent.getIntent("intent://map/direction?" +
//                                                        "origin=latlng:"+latitudeNow+","+LongitudeNow+
//                                                        "&destination=latlng:"+Float.valueOf(weidu)+","+Float.valueOf(jingdu)+"|name:我的目的地"+        //终点
//                                                        "&mode=driving&" +          //导航路线方式
//                                                        "region=北京" +           //
//                                                        "&src=翠微e生活#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");

//

                                                openBaiduMap(latitudeNow,LongitudeNow,"我的位置",Float.valueOf(weidu),Float.valueOf(jingdu),"目的地","");

                                            } catch (Exception e) {
                                                Log.e("intent", e.getMessage());
                                            }
                                        } else if (maps[which].equals("谷歌地图")) {
                                            Uri gmmIntentUri = Uri.parse("google.navigation:q=" + jingdu + "," + weidu + ", + BeiJing +China");
                                            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                                            mapIntent.setPackage("com.google.android.apps.maps");
                                            ExtWebDetailActivity.this.startActivity(mapIntent);
                                        } else if (maps[which].equals("高德地图")) {
                                            Log.e("1111", "打开高德地图");
                                            try {

                                                MLog.i("LatitudeNow",latitudeNow+"");
                                                MLog.i("LongitudeNow",LongitudeNow+"");

                                                Intent intent = Intent.getIntent("androidamap://route?sourceApplication="+"翠微e生活"+"&slat="+latitudeNow1+"&slon="+LongitudeNow1+"&sname="+"我的位置"+"&dlat="+latitudeNow2+"&dlon="+LongitudeNow2+"&dname="+"目的地"+"&dev=0&m=0&t=1");
                                                ExtWebDetailActivity.this.startActivity(intent);
                                            } catch (URISyntaxException e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    }
                                });
                                builder.show();
                            } else {
                                Log.e("1111", "没有地图");
                                Toast.makeText(ExtWebDetailActivity.this, "您尚未安装地图APP", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });


这个要主要,在百度地图地图和谷歌,高德地图的时候,需要转换坐标系,不然导航的位置就不是很准确了。

https://blog.csdn.net/a13570320979/article/details/51366355#




猜你喜欢

转载自blog.csdn.net/Andybfw/article/details/80321845
今日推荐