Android integrates high moral map navigation SDK, achieved within the App Navigate to open high moral Navigation App

This article will mainly speaking about the integration of high moral navigation SDK, achieved within the app navigation; so do not call the high moral App

First, the application of such key here is not to say it is ok to apply themselves

Second, I downloaded the SDK that follows, 3D mapping and navigation SDK only two

Here Insert Picture Description

Third, configure the project into navigation SDK and so library files

Here Insert Picture Description

  • Configuring Manifest.xmladd permissions
<!--用于访问网络,网络定位需要上网-->
<uses-permission android:name="android.permission.INTERNET" />
<!--写入扩展存储,向扩展卡写入数据,用于写入缓存定位数据-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--获取运营商信息,用于支持提供运营商信息相关的接口-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--用于访问GPS定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!--用于读取手机当前的状态-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--用于访问wifi网络信息,wifi信息会用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!--这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!--这个权限用于允许程序在手机屏幕关闭后后台进程仍然运行-->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
  • Configuration Manifest.xml, add the SDK key and high moral navigation Activity
<meta-data
    android:name="com.amap.api.v2.apikey"
    android:value="你申请的KEY" />
    
<!--导航组件Activity-->
<activity
    android:name="com.amap.api.navi.AmapRouteActivity"
    android:configChanges="orientation|keyboardHidden|screenSize
    android:theme="@android:style/Theme.NoTitleBar" />

Fourth, because I have no need to customize the navigation needs so the direct use of high German navigation components packaged directly

Navigation components - document address

Initiate navigation: Given a starting point, via point, end point

  • If you do not pass the starting point, it will use the current location
  • Waypoints can not pass
	/**
     * 路线规划
     *
     * @param slat 起点纬度
     * @param slon 起点经度
     * @param dlat 终点纬度
     * @param dlon 终点经度
     */
    public void navigation(Context context, double slat, double slon, double dlat, double dlon) {
        Poi start = null;
        //如果设置了起点
        if (slat != 0 && slon != 0) {
            start = new Poi("起点名称", new LatLng(slat, slon), "");
        }
        Poi end = new Poi("终点名称", new LatLng(dlat, dlon), "");
        AmapNaviParams params = new AmapNaviParams(start, null, end, AmapNaviType.DRIVER);
        params.setUseInnerVoice(true);
        params.setMultipleRouteNaviMode(true);
        params.setNeedDestroyDriveManagerInstanceWhenNaviExit(true);
        //发起导航
        AmapNaviPage.getInstance().showRouteActivity(context, params, null);
    }

Fifth, look at the results achieved: First, he will first look at the route plan and then you can launch the navigation and use of high German App is the same

Six, Android App tune from high German navigation will not integrate SDK, as follows:

public class AMapUtil {

    /**
     * 路线规划
     *
     * @param slat 起点纬度
     * @param slon 起点经度
     * @param dlat 终点纬度
     * @param dlon 终点经度
     */
    public static void route(Context context, String slat, String slon, String dlat, String dlon) {
        if (isInstallApp(context, "com.autonavi.minimap")) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setPackage("com.autonavi.minimap");
            String uri = "androidamap://route?" + "sourceApplication=" + context.getString(R.string.app_name);
            //如果设置了起点
            if (!TextUtils.isEmpty(slat) && !TextUtils.isEmpty(slon)) {
                uri += "&slat=" + slat + "&slon=" + slon;
            }
            uri += "&dlat=" + dlat +
                    "&dlon=" + dlon +
                    "&dev=" + 0 +
                    "&t=" + 0 +
                    "&t=" + 0;
            intent.setData(Uri.parse(uri));
            context.startActivity(intent);
        } else {
            String uri = "https://uri.amap.com/navigation?";
            //如果设置了起点
            if (!TextUtils.isEmpty(slat) && !TextUtils.isEmpty(slon)) {
                uri += "from=" + slon + "," + slat + ",起点";
            }
            uri += "&to=" + dlon + "," + dlat + ",终点" +
                    "&mode=car";
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(uri));
            context.startActivity(intent);
        }
    }

    /**
     * 检测应用是否安装
     */
    public static boolean isInstallApp(Context context, String packageName) {
        PackageInfo packageInfo;
        try {
            packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
        } catch (Exception e) {
            packageInfo = null;
            e.printStackTrace();
        }
        return packageInfo != null;
    }
}

To say finished here can have fun playing the ...

Published 140 original articles · won praise 546 · views 540 000 +

Guess you like

Origin blog.csdn.net/a_zhon/article/details/90787556