Android App calls Baidu Map, Golden Map and Tencent Map for destination navigation

Keywords: Android Amap Mobile SDK

Android App skips Baidu Map, Golden Map and Tencent Map for destination navigation.

Put Baidu, Gaode and Tencent maps on the first place to call API document address, some parameters do not understand can be referred to.

Baidu Maps: http://lbsyun.baidu.com/index.php?title=uri/api/android

Golden Map: https://lbs.amap.com/api/amap-mobile/guide/android/navigation

Tencent Map: http://lbs.qq.com/uri_v1/guide-mobile-navAndRoute.html

1. Coordinate System

Types of 1.1 Coordinate System

At present, there are three coordinate systems: WGS84, GCJ02 and BD09. The latter two are basically used in China.

WGS84: International coordinate system, which is a geodetic coordinate system, is also the coordinate system widely used in GPS Global Satellite Positioning System.
GCJ02: Mars coordinate system is a coordinate system of geographic information system formulated by China National Bureau of Surveying and Mapping. The WGS84 coordinate system is encrypted. Gaode and Tencent all use this.
BD09: Baidu coordinate system, encrypted again on the basis of GCJ02 coordinate system. Among them, BD09ll represents the longitude and latitude coordinates of Baidu, and BD09mc represents the Mercator metric coordinates of Baidu. The default output of Baidu map sdk is BD09ll, and the default output of positioning sdk is GCJ02.

1.2 Coordinate System Conversion

Calling Gaode Map and Tencent Map needs to pass in coordinates of GCJ02 coordinate system, and calling Baidu Map needs to pass in coordinates of BD09 coordinate system. Because my project uses the Baidu map sdk, so calling the map of Gaode and Tencent needs to transform the coordinate format.

The methods of conversion between the two coordinate systems are as follows.

 /**
     * BD-09 Conversion of coordinates to GCJ-02 coordinates
     */
    public static LatLng BD2GCJ(LatLng bd) {
        double x = bd.longitude - 0.0065, y = bd.latitude - 0.006;
        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * Math.PI);
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * Math.PI);

        double lng = z * Math.cos(theta);//lng
        double lat = z * Math.sin(theta);//lat
        return new LatLng(lat, lng);
    }

    /**
     * GCJ-02 Converting coordinates to BD-09 coordinates
     */
    public static LatLng GCJ2BD(LatLng bd) {
        double x = bd.longitude, y = bd.latitude;
        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * Math.PI);
        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * Math.PI);
        double tempLon = z * Math.cos(theta) + 0.0065;
        double tempLat = z * Math.sin(theta) + 0.006;
        return new LatLng(tempLat, tempLon);
    }

2. Call jump third-party map for navigation

2.1 Check whether third-party maps are installed

Before invoking the jump third-party map for navigation, it is necessary to check whether the mobile phone has a third-party map to jump. The detection method is as follows: if the installation returns true, otherwise it returns false.

/**
     * Check whether the program is installed
     *
     * @param packageName
     * @return
     */
    private boolean isInstalled(String packageName) {
        PackageManager manager = mContext.getPackageManager();
        //Get package information for all installed programs
        List<PackageInfo> installedPackages = manager.getInstalledPackages(0);
        if (installedPackages != null) {
            for (PackageInfo info : installedPackages) {
                if (info.packageName.equals(packageName))
                    return true;
            }
        }
        return false;
    }

2.2 Jump to third-party maps and pass them on

2.2.1 Baidu Map

First, jump Baidu Map. According to the documents of Baidu Map, we know that the URL interface of Baidu Map Navigation is

URL interface: baidumap://map/navi

The parameters to be passed are

Parameter name describe Is it necessary? Format (example)
location There must be one coordinate point, location and query. When there is location, query is ignored; the coordinate type refers to the general parameter: coord_type. Optional Latitude and longitude: 39.9761, 116.3282
query Search key, location and query must have one. When there is location, query is ignored; coordinate type refers to general parameter: coord_type. Optional The Imperial Palace
type Route planning type, BLK: avoid congestion (self-driving); TIME: high-speed priority (self-driving); DIS: do not take high-speed (self-driving); FEE: less charge (self-driving); DEFAULT: do not choose preferences; empty or no field: use the route preferences saved in the map (default value). Optional  
src Statistical sources Mandatory The parameter format is: andr.companyName.appName
Do not pass this parameter, do not guarantee service

 

 

 

 

 

 

 

 

 

Examples of official document code usage

Intent i1 = new Intent();

// Nokia Drivers

i1.setData(Uri.parse("baidumap://map/navi?query = Forbidden City & SRC = andr. baidu. openAPIdemo ");

startActivity(i1);

Above is the description of Baidu documents, but I look at the code on the Internet, some parameters can be passed without stipulation. I use the method of jumping Baidu Map as follows

    /**
     * Jump Baidu Map
     */
    private void goToBaiduMap() {
        if (!isInstalled("com.baidu.BaiduMap")) {
            T.show(mContext, "Please install Baidu Map Client first");
            return;
        }
        Intent intent = new Intent();
        intent.setData(Uri.parse("baidumap://map/direction?destination=latlng:"
                + mLat + ","
                + mLng + "|name:" + "" + // End
                "&mode=driving" + // Navigation route
                "&src=" + getPackageName()));
        startActivity(intent); // Startup call
    }

2.2.2 Gaud Map

Examples of official document code usage

cat=android.intent.category.DEFAULT
dat=androidamap://navi?sourceApplication=appname&poiname=fangheng&lat=36.547901&lon=104.258354&dev=1&style=2
pkg=com.autonavi.minimap

Parameter description

parameter Explain Is it necessary to fill in?
navi Service type yes
sourceApplication The third party calls the application name. Such as amap yes
poiname POI name no
lat latitude yes
lon longitude yes
dev Whether or not the offset (0:lat and lon are encrypted and need not be encrypted by national test; 1: need to be encrypted by national test) yes
style Navigation modes (0 fast; 1 low cost; 2 short distance; 3 not high-speed; 4 avoid congestion; 5 not high-speed and avoid charges; 6 not high-speed and avoid congestion; 7 avoid charges and congestion; 8 not high-speed to avoid charges and congestion) yes

 

 

 

 

 

 

 

 

 

The Skipping Goethe Map Navigation Method I Used

   
    /**
     * Jump Golden Map
     */
    private void goToGaodeMap() {
        if (!isInstalled("com.autonavi.minimap")) {
            T.show(mContext, "Please install Golden Map Client first");
            return;
        }
        LatLng endPoint = BD2GCJ(new LatLng(mLat, mLng));//coordinate transformation
        StringBuffer stringBuffer = new StringBuffer("androidamap://navi?sourceApplication=").append("amap");
        stringBuffer.append("&lat=").append(endPoint.latitude)
                .append("&lon=").append(endPoint.longitude)
                .append("&dev=").append(0)
                .append("&style=").append(2);
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(stringBuffer.toString()));
        intent.setPackage("com.autonavi.minimap");
        startActivity(intent);
    }

But there's a problem with my jumping around. It's always in the display positioning. If you have a friend who knows the reason, you can confide in me.

2.2.3 Tencent Map

Android and iOS call addresses:

qqmap://map/routeplan

Examples of official document code usage

//Call up Tencent Map APP to show the driving route from Tsinghua University to Yihe Shijia District 
qqmap://Map / routeplan? Type = drive & from = Tsinghua & fromcoord = 39.994745, 116.247282 & to = Yihe family & tocoord = 39.867192, 116.493187 & referer = OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77

Parameter description

parameter Must fill Explain Example
type yes Route planning mode parameters:
Bus: bus
Driving: drive
Walking: walk
Riding: bike
type=bus or type=drive or type = wall or type=bike
from no Starting name from= Drum Tower
fromcoord yes Starting point coordinates, format: lat,lng (latitude before, longitude after, comma-separated)
Functional parameter value: Current Location: Use location point as starting point coordinate
fromcoord=39.907380,116.388501 
fromcoord=CurrentLocation
to no End name to = Olympic Forest Park
tocoord yes Terminal coordinates tocoord=40.010024,116.392239
referer yes Please fill in the developer key. [Click on this application] referer=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77

 

 

 

 

 

 

 

 

 

 

 

After many attempts, I found that only type and tocoord can be passed, it will default to locate the starting point for your current location.

    /**
     * Jump Tencent Map
     */
    private void goToTencentMap() {
        if (!isInstalled("com.tencent.map")) {
            T.show(mContext, "Please install Tencent Map Client first");
            return;
        }
        LatLng endPoint = BD2GCJ(new LatLng(mLat, mLng));//coordinate transformation
        StringBuffer stringBuffer = new StringBuffer("qqmap://map/routeplan?type=drive")
                .append("&tocoord=").append(endPoint.latitude).append(",").append(endPoint.longitude);
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(stringBuffer.toString()));
        startActivity(intent);
    }

3, summary

To invoke the third-party map navigation, we must first make sure that we are using the coordinate system. If the coordinate system is incorrect, the position navigation will be biased. Baidu and Tencent are relatively simple to use, combined with documents and online examples is easy to achieve, but Golden when I use it is more troublesome, for example, I do not know why has been positioning, can not navigate. If you want to know something, you can tell me about it.

Posted by jmicozzi on Fri, 17 May 2019 11:36:10 -0700