One article deals with the route planning and smooth movement of cars in Tencent map development

preface

Developers in the online car Hailing industry need to use LBS (location-based service), that is, location-based services. Baidu map, Tencent map and Gaode map provide LBS services in China. This paper selects Tencent map's LBS, that is, Tencent location service. This demo can realize basic functions such as route planning and car smoothing.

Implementation steps

Let's take a look at the implementation effect:

Create a new Android project and an Activity named drivengrouteactivity. First, draw the UI layout. The layout is relatively simple. It consists of a map component MapView under Tencent SDK package, two input boxes for inputting the starting position, two buttons for confirming route planning, an ImageView for locating the current position and a TextView for displaying travel information, The layout code is only for the convenience of displaying and realizing functions, so the layout code is posted directly below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".activity.DrivingRouteActivity">
 
    <com.tencent.tencentmap.mapsdk.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
 
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="bottom"
        android:paddingTop="10dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <EditText
                android:id="@+id/from_et"
                android:hint="Where do you get on the bus"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"
                android:layout_width="match_parent"
                android:layout_height="50dp"></EditText>
            <ImageButton
                android:id="@+id/location_ib"
                android:background="@drawable/sendtocar_balloon"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_marginRight="10dp"
                android:layout_width="50dp"
                android:layout_height="50dp"></ImageButton>
        </LinearLayout>
        <EditText
            android:id="@+id/to_et"
            android:hint="Where are you going"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"></EditText>
        <TextView
            android:id="@+id/orderdesc_tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="20sp"></TextView>
        <Button
            android:id="@+id/confirm_btn"
            android:text="determine"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:visibility="gone"></Button>
        <Button
            android:id="@+id/order_btn"
            android:text="Book Express"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"></Button>
    </LinearLayout>
 
</LinearLayout>

1. Account registration and configuration

Before development, we need to register an account on the official website of Tencent location service
Enter the console after registration
Select key management, click create new secret key, and submit the application according to the application information

Configure the above requested key under the application tab as follows (replace value with your own key)

<meta-data
    android:name="TencentMapSDK"
    android:value="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" />

2. Introduce Tencent Android map SDK

Enter the Android map SDK and download the 3D map SDK package
After the download is completed, open the compressed package, copy the jar package under the libs folder to the libs directory of the app, right-click the jar package, select add as library to add it as a dependency, establish a directory named jniLibs under the project app\src\main path, and put all packages under the libs/jniLibs/strip folder of the compressed package into the jniLibs directory
After importing, configure relevant permissions in the AndroidManifest.xml file

<!-- Access the web for map services -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Check network availability -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- visit WiFi state -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- External storage write permission is required to save the map cache -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- obtain device id Discrimination device -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

3. Map initialization

After the configuration is completed, we will now start to realize our logical interaction. In order to make the implementation logic clearer, I divided the business logic code and View rendering code into two packages. In addition to the drivengrouteactivity in the activity package, I created a new present package and created a drivengroutepresent class under the package, Respectively, drivengrouteactivity is responsible for rendering the View of UI components, and drivengroutepresent class is responsible for business logic. Here, I also create a new contract package and a drivengroutecontract interface. Through the methods defined by this interface, I can realize the interaction between drivengroutepresent and drivengrouteactivity. We define two interfaces in the drivengroutecontract interface, a View interface for drivengrouteactivity and a Presenter interface for drivengroutepresent, and define some initialization methods

public interface DrivingRouteContract {
    
    interface View{
        void initView();//Initialize View
        void initOnClick();//Initialize OnClickListener
        void setOrderDescTV(String content);//Render order itinerary information
        EditText getFromET();
    }
 
    interface Presenter{
        void attachView(DrivingRouteContract.View view);//Bind View
    }
}

Then let the drivengrouteactivity implement the drivengroutecontract.view interface and declare the components in the UI for initialization

public class DrivingRouteActivity extends Activity implements DrivingRouteContract.View, View.OnClickListener {
    private MapView mapView;
    private TencentMap mMap;
    private Button confirmBtn;
    private Button orderBtn;
    private ImageButton locationIB;
    private EditText fromET;
    private EditText toET;
    private TextView orderDescTV;
   private DrivingRoutePresent drivingRoutePresent;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_driving_route);
        initView();
        initOnClick();
    }
 
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.order_btn:
                //Realize travel route planning
                break;
            case R.id.confirm_btn:
                //Turn on animation movement
                break;
            case R.id.location_ib:
                //Locate current position
                break;
        }
    }
 
    /**
     * mapview Life cycle management
     */
    @Override
    protected void onStart() {
        super.onStart();
        mapView.onStart();
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }
 
    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }
 
    @Override
    protected void onStop() {
        super.onStop();
        mapView.onStop();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }
 
    @Override
    protected void onRestart() {
        super.onRestart();
        mapView.onRestart();
    }
 
    @Override
    public void initView() {
        mapView = findViewById(R.id.mapview);
        confirmBtn = findViewById(R.id.confirm_btn);
        orderBtn = findViewById(R.id.order_btn);
        locationIB = findViewById(R.id.location_ib);
        fromET = findViewById(R.id.from_et);
        toET = findViewById(R.id.to_et);
        orderDescTV = findViewById(R.id.orderdesc_tv);
        mMap = mapView.getMap();
 
        drivingRoutePresent = new DrivingRoutePresent();
        drivingRoutePresent.attachView(this);
    }
 
    @Override
    public void initOnClick() {
        orderBtn.setOnClickListener(this);
        confirmBtn.setOnClickListener(this);
        locationIB.setOnClickListener(this);
    }
    
    @Override
    public void setOrderDescTV(String content) {
        orderDescTV.setText(content);
    }
 
    @Override
    public EditText getFromET() {
        return fromET;
    }
}

Drivengroutepresent implements the drivengroutecontract.presenter interface

public class DrivingRoutePresent implements DrivingRouteContract.Presenter {
    
    private DrivingRouteContract.View drinvingRouteView;
    
    @Override
    public void attachView(DrivingRouteContract.View view) {
        drinvingRouteView = view;
    }
}

Because we need to use the current application context in many places later, for convenience, we need to write a global application context tool class to help us obtain the context, establish a util package and create a GlobalApplication class

public class GlobalApplication extends Application {
 
    private static Context context;
 
    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
    }
 
    public static Context getContext(){
        return context;
    }
}

At the same time, add the following attributes to the application tag of Android class file to enable the above GlobalApplication to be loaded when the application starts

android:name=".util.GlobalApplication"

Here, we have completed the basic design of the interface and business code. Run the app to see the basic map information displayed. Next, let's realize the function of route planning. Tencent's official Android map SDK development document provides a detailed description of route planning services and address resolution.
A call example Demo is also provided. If you don't know how to call it, you can refer to the official Demo or the following code.

4. Address resolution and route planning

First, we declare a geocoder method for finding latitude and longitude through address and a routePlan method for route planning in the drivengroutecontract. Presenter interface

public interface DrivingRouteContract {
    
    interface View{
        void initView();//Initialize View
        void initOnClick();//Initialize OnClickListener
        void setOrderDescTV(String content);//Render order itinerary information
        EditText getFromET();
    }
 
    interface Presenter{
        void attachView(DrivingRouteContract.View view);//Bind View
        void geocoder(String address, Integer type);//Address decoding, to latitude and longitude
        void routePlan();//Realize route planning
    }
}

Through the development documents of Tencent Android map SDK route planning service, we learned that to obtain the planned route, we need to obtain the longitude and latitude of the starting point and the ending point first. In general business scenarios, we almost don't let users manually enter the longitude and latitude, so I also need to use the address resolution service here to obtain the longitude and latitude by entering a Chinese address, Then plan the route through longitude and latitude (however, in the actual business, it is best to add the keyword input prompt service to facilitate users to find the input location).

Implement these two methods in the drivengroutepresent class

public static final Integer FROM_TYPE = 0x100; //Get start position coordinates
public static final Integer TO_TYPE = 0x101; //Get destination coordinates
private LatLng fromLatLng;
private LatLng toLatLng;
 
/**
 * Address decoding
 * @param address Pass in the address to be decoded
 * @param type Address type, start location, destination location
 */
@Override
public void geocoder(String address, final Integer type) {
    TencentSearch tencentSearch = new TencentSearch(GlobalApplication.getContext());
    Address2GeoParam address2GeoParam =
            new Address2GeoParam(address);
    tencentSearch.address2geo(address2GeoParam, new HttpResponseListener<BaseObject>() {
 
        @Override
        public void onSuccess(int arg0, BaseObject arg1) {
            if (arg1 == null) {
                return;
            }
            Address2GeoResultObject obj = (Address2GeoResultObject)arg1;
            if (obj.result.latLng != null) {
                if (type==FROM_TYPE)
                    fromLatLng = obj.result.latLng;
                else if (type==TO_TYPE)
                    toLatLng = obj.result.latLng;
                routePlan();
            }
        }
 
        @Override
        public void onFailure(int arg0, String arg1, Throwable arg2) {
            Log.e("test", "error code:" + arg0 + ", msg:" + arg1);
        }
    });
}
 
private TencentSearch tencentSearch = new TencentSearch(GlobalApplication.getContext());
private StringBuffer lineStringBuilder = new StringBuffer();//Route Coordinates
private Double taxiFare = 0d;//Estimated taxi cost
private Float distance = 0f;//Estimated total mileage
 
/**
 * Route planning
 */
@Override
public void routePlan() {
    if (fromLatLng!=null&&toLatLng!=null){
        Toast.makeText(GlobalApplication.getContext(), "Planning your route", Toast.LENGTH_SHORT).show();
        DrivingParam drivingParam = new DrivingParam(fromLatLng, toLatLng);
        drivingParam.policy(DrivingParam.Policy.TRIP);//Driving route planning strategy, online car Hailing scene, seeing off passengers
        drivingParam.setCarNumber("Guangdong A00001");//Fill in the license plate number and avoid the license plate restricted area during route planning
        tencentSearch.getRoutePlan(drivingParam, new HttpResponseListener<DrivingResultObject>() {
 
            @Override
            public void onSuccess(int i, DrivingResultObject drivingResultObject) {
                for (DrivingResultObject.Route route : drivingResultObject.result.routes){
                    for (LatLng latLng : route.polyline){
                        lineStringBuilder.append(latLng.latitude + "," + latLng.longitude);
                        lineStringBuilder.append(",");
                    }
                    distance += route.distance;
                    taxiFare += route.taxi_fare.fare;
                }
                drinvingRouteView.setOrderDescTV("Travel approx" + distance + "m,estimateĀ„" + taxiFare + "element");
 
                //Clear the travel route, mileage and expense information
                lineStringBuilder = new StringBuffer();
                distance = 0f;
                taxiFare = 0d;
            }
 
            @Override
            public void onFailure(int i, String s, Throwable throwable) {
                Log.d("DrivingRouteActivity", "onSuccess: " + s + i);
            }
        });
 
        fromLatLng=null;
        toLatLng=null;
    }
}

The geocoder method is used to get the starting position of the input (where to get on the train), and the coordinate longitude and latitude of the destination location (where to get off). After recording the longitude and latitude of the location, it calls the routePlan method to request the route planning interface, and records the mileage, the cost information, and the longitude and latitude of the points that are passing through the course of the route (for the car to move behind).

In addition to several common parameters used above, the route planning interface also has many interface parameters. For details, you can view the official interface document and add them as needed

Refer to the official interface document: https://lbs.qq.com/AndroidDocs/doc_3d/index.html

5. Vehicle Driving animation

With the route planning method, add an implementation to the "reserve express" button

@Override
public void onClick(View view) {
    switch (view.getId()){
        case R.id.order_btn:
            drivingRoutePresent.geocoder(fromET.getText().toString(), DrivingRoutePresent.FROM_TYPE);
            drivingRoutePresent.geocoder(toET.getText().toString(), DrivingRoutePresent.TO_TYPE);
            confirmBtn.setVisibility(View.VISIBLE);
            orderBtn.setVisibility(View.GONE);
            break;
        case R.id.confirm_btn:
            //Turn on animation movement
            break;
        case R.id.location_ib:
            //Locate current position
            break;
    }
}

At this time, run the APP and input the starting point and ending point to obtain the planned driving route

Next, let's realize the function of the trolley driving according to the planned route on the renderings

Add the car animation initialization method initAnimation in the drivengroutecontract.view interface

public interface DrivingRouteContract {
 
    interface Model{
    }
 
    interface View{
        void initView();//Initialize View
        void initOnClick();//Initialize OnClickListener
        void setOrderDescTV(String content);//Render order itinerary information
        EditText getFromET();
        void initAnimation(String line);//Initialize trolley movement animation
    }
 
    interface Presenter{
        void attachView(DrivingRouteContract.View view);//Bind View
        void startLocation(boolean single);
        void stopLocation();
        void geocoder(String address, Integer type);//Address decoding, to latitude and longitude
        void routePlan();//Realize route planning
    }
}

The initAnimation method is implemented. For other parameters of Marker, please also refer to the interface document above

private Marker mCarMarker;
private LatLng[] mCarLatLngArray;
private MarkerTranslateAnimator mAnimator;
 
@Override
public void initAnimation(String line) {
    //Split to obtain longitude and latitude array
    String[] linePointsStr = line.split(",");
    mCarLatLngArray = new LatLng[linePointsStr.length / 2];
    for (int i = 0; i < mCarLatLngArray.length; i++) {
        double latitude = Double.parseDouble(linePointsStr[i * 2]);
        double longitude = Double.parseDouble(linePointsStr[i * 2 + 1]);
        mCarLatLngArray[i] = new LatLng(latitude, longitude);
    }
 
    //Add trolley route
    mMap.addPolyline(new PolylineOptions().add(mCarLatLngArray)
        .color(R.color.colorLine));//This color is a custom color in colors.xml
 
    //Add trolley
    LatLng carLatLng = mCarLatLngArray[0];
    mCarMarker = mMap.addMarker(
            new MarkerOptions(carLatLng)
                    .anchor(0.5f, 0.5f)
                    .icon(BitmapDescriptorFactory.fromResource(R.mipmap.taxi_t))//Trolley Icon
                    .flat(true)
                    .clockwise(false));
 
    //Create mobile animation
    mAnimator = new MarkerTranslateAnimator(mCarMarker, 50 * 1000, mCarLatLngArray, true);
 
    //Adjust the best view
    mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(
            LatLngBounds.builder().include(Arrays.asList(mCarLatLngArray)).build(), 50));
}

This method is called in the routePlan method, and the incoming route string is passed in.

//Initialize car animation
drinvingRouteView.initAnimation(lineStringBuilder.substring(0, lineStringBuilder.length()-1));

Full code reference

/**
 * Route planning
 */
@Override
public void routePlan() {
    if (fromLatLng!=null&&toLatLng!=null){
        Toast.makeText(GlobalApplication.getContext(), "Planning your route", Toast.LENGTH_SHORT).show();
        DrivingParam drivingParam = new DrivingParam(fromLatLng, toLatLng);
        drivingParam.policy(DrivingParam.Policy.TRIP);//Driving route planning strategy, online car Hailing scene, seeing off passengers
        drivingParam.setCarNumber("Guangdong A00001");//Fill in the license plate number and avoid the license plate restricted area during route planning
        tencentSearch.getRoutePlan(drivingParam, new HttpResponseListener<DrivingResultObject>() {
 
            @Override
            public void onSuccess(int i, DrivingResultObject drivingResultObject) {
                for (DrivingResultObject.Route route : drivingResultObject.result.routes){
                    for (LatLng latLng : route.polyline){
                        lineStringBuilder.append(latLng.latitude + "," + latLng.longitude);
                        lineStringBuilder.append(",");
                    }
                    distance += route.distance;
                    taxiFare += route.taxi_fare.fare;
                }
                //Initialize car animation
                drinvingRouteView.initAnimation(lineStringBuilder.substring(0, lineStringBuilder.length()-1));
                drinvingRouteView.setOrderDescTV("Travel approx" + distance + "m,estimateĀ„" + taxiFare + "element");
 
                //Clear the travel route, mileage and expense information
                lineStringBuilder = new StringBuffer();
                distance = 0f;
                taxiFare = 0d;
            }
 
            @Override
            public void onFailure(int i, String s, Throwable throwable) {
                Log.d("DrivingRouteActivity", "onSuccess: " + s + i);
            }
        });
 
        fromLatLng=null;
        toLatLng=null;
    }
}

Finally, we call the startAnimation method of MarkerTranslateAnimator on the click event of the "OK" button to start the animation

@Override
public void onClick(View view) {
    switch (view.getId()){
        case R.id.order_btn:
            drivingRoutePresent.geocoder(fromET.getText().toString(), DrivingRoutePresent.FROM_TYPE);
            drivingRoutePresent.geocoder(toET.getText().toString(), DrivingRoutePresent.TO_TYPE);
            confirmBtn.setVisibility(View.VISIBLE);
            orderBtn.setVisibility(View.GONE);
            break;
        case R.id.confirm_btn:
            //Turn on animation movement
            mAnimator.startAnimation();
            orderBtn.setVisibility(View.VISIBLE);
            confirmBtn.setVisibility(View.GONE);
            break;
        case R.id.location_ib:
            //Locate current position
            break;
    }
}

6. Introduce Tencent Android positioning SDK

The basic effect has been completed, and the last positioning function is still missing. To realize the positioning function, another SDK (Android positioning SDK) needs to be introduced

We open the Android SDK development document and download the latest SDK
Put the jar package in the compressed package under the libs package of app and add it as a dependency
Then copy all so files in the libs folder of the compressed package to the corresponding directory of the project jniLibs
Open the AndroidManifest.xml file and add the following permission configuration

<!-- adopt GPS Get the exact position -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Get rough location through the network -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- access networks. Some location information needs to be obtained from the network server -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- visit WiFi state. need WiFi Information for network positioning -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- modify WiFi state. launch WiFi scanning, need WiFi Information for network positioning -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- Access network status, Detect network availability. Network operator related information is required for network positioning -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Changes in access to the network, Some information is needed for network location -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<!-- Access the current status of the phone, need device id For network location -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- support A-GPS Auxiliary positioning -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<!-- be used for log journal -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

7. Display current positioning

After configuration, we add a startLocation to start positioning and a stopLocation method to end positioning in the drivengroutecontract. Presenter interface

void startLocation(boolean single);
void stopLocation();

Implement the drivengroutepresent method again

private boolean IS_SINGLE_LOCATION_MODE = false;//Continuous positioning
private TencentLocationManager mLocationManager = TencentLocationManager.getInstance(GlobalApplication.getContext());
private TencentLocationRequest locationRequest;
 
@Override
public void startLocation(boolean single) {
    IS_SINGLE_LOCATION_MODE = single;//Because it only needs to be located once, a parameter is added
    locationRequest = TencentLocationRequest.create();
    locationRequest.setInterval(5000);//Positioning interval
    //According to the detail of the location information obtained by the user, REQUEST_LEVEL_ADMIN_AREA: contains latitude and longitude, and the location of China's administrative divisions.
    locationRequest.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_ADMIN_AREA);
    locationRequest.setAllowGPS(true);//Is GPS positioning allowed
    mLocationManager.requestLocationUpdates(locationRequest, this);//Continuous positioning
}
 
@Override
public void stopLocation() {
    mLocationManager.removeUpdates(this);
}

In addition, in order to obtain the location information of positioning, we also need to let drivengroutepresent additionally implement the TencentLocationListener interface, and implement onLocationChanged (for receiving positioning results) and onstatus update (for receiving status codes of GPS, WiFi and cell).

@Override
    public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
        if (IS_SINGLE_LOCATION_MODE)
            stopLocation();
        switch (i){
            case TencentLocation.ERROR_OK:
                //Successful positioning
                drinvingRouteView.setLocation(tencentLocation);
                //Render location information
                if (drinvingRouteView.getFromET()!=null&&drinvingRouteView.getFromET().getText().toString().trim().equals(""))
                    drinvingRouteView.getFromET().setText(tencentLocation.getAddress());
//                Toast.makeText(GlobalApplication.getContext(), "positioning succeeded", Toast.LENGTH_SHORT).show();
                break;
            case TencentLocation.ERROR_NETWORK:
                Toast.makeText(GlobalApplication.getContext(), "Positioning failure caused by network problems", Toast.LENGTH_SHORT).show();
                break;
            case TencentLocation.ERROR_BAD_JSON:
                Toast.makeText(GlobalApplication.getContext(), "GPS, Wi-Fi Or location failure caused by base station error", Toast.LENGTH_SHORT).show();
                break;
            case TencentLocation.ERROR_WGS84:
                Toast.makeText(GlobalApplication.getContext(), "Unable to WGS84 Coordinate conversion to GCJ-02 Positioning at coordinates failed", Toast.LENGTH_SHORT).show();
                break;
            case TencentLocation.ERROR_UNKNOWN:
                Toast.makeText(GlobalApplication.getContext(), "Location failure due to unknown reason", Toast.LENGTH_SHORT).show();
                break;
        }
    }
 
    @Override
    public void onStatusUpdate(String s, int i, String s1) {
        //TencentLocationListener calls back the GPS, WiFi and cell status codes passed in by this method. For specific status codes, see the Android positioning SDK development documents
    }

Finally, we add the implementation of the click event bound to the located small button, and call the startLocation and stopLocation methods in the onResume and onPause methods to make the app locate automatically when opening or switching back to the current Activity

@Override
public void onClick(View view) {
    switch (view.getId()){
        case R.id.order_btn:
            drivingRoutePresent.geocoder(fromET.getText().toString(), DrivingRoutePresent.FROM_TYPE);
            drivingRoutePresent.geocoder(toET.getText().toString(), DrivingRoutePresent.TO_TYPE);
            confirmBtn.setVisibility(View.VISIBLE);
            orderBtn.setVisibility(View.GONE);
            break;
        case R.id.confirm_btn:
            //Turn on animation movement
            mAnimator.startAnimation();
            orderBtn.setVisibility(View.VISIBLE);
            confirmBtn.setVisibility(View.GONE);
            break;
        case R.id.location_ib:
            //Positioning once
            drivingRoutePresent.startLocation(true);
            break;
    }
}
 
@Override
protected void onResume() {
    super.onResume();
    mapView.onResume();
    drivingRoutePresent.startLocation(true);
}
 
@Override
protected void onPause() {
    super.onPause();
    mapView.onPause();
    drivingRoutePresent.stopLocation();
}

ending

After writing here, all the functions on the rendering are basically completed. Generally speaking, the functions are still very powerful. For enterprises with relevant needs, it is very time-saving and labor-saving to develop. In addition, the development documents and interface documents are also more detailed. Due to limited time, I have only experienced a few of these services for the time being. Students with more needs can explore on the official website by themselves.

Tags: Android lbs

Posted on Sat, 18 Sep 2021 03:29:38 -0400 by Eggzorcist