preface

When using a taxi app to take a taxi, we will be curious about how the passenger’s mobile phone is not navigating when the driver is delivering the passenger. Today we are going to unveil its mystery

The preparatory work

To achieve this function, we still need Tencent location service family barrel: Tencent navigation SDK, Tencent map SDK, Tencent positioning SDK, Tencent Company and ride with display SDK, the opening of specific permissions need to go to the official website console of Lbs.qq.com, to operate the other specific SDK permissions can contact small assistant consultation (as shown below), here will not do more discussion!

The specific implementation

Use the core map tool to rely on the library

Implementation 'com.0700. map: 0700-map-vector-sdk :4.4.2' Including trolley translation, point polymerization and other component functions, see the development guide. Must!! Implementation 'com.tencent. Map: SDK-utilities :1.0.6 Files ('libs/ tencentlocationsdk_v8.4.14_ra0311232_20200103_125837_release.aar ') You can get the implementation Files ('libs/ lSPassenger_v2.0.1_04.03.aar ') implementation from the official website of Tencent Location Service Center Files ('libs/ lsSupport_v2.0.1_04.03.aar ') // Base library. Implementation 'com.0700. map: 0700-map-nav-surport :1.0.2.3'}Copy the code

Flow chart presentation

According to the above flow chart, we know that in order to realize the smooth movement of the car, we need to continuously obtain the driver’s points in the last few seconds and the current route. The specific process is that the driver will synchronize the route and GPS points in the last few seconds through the DRIVER’s SDK when the driver starts to show the smooth movement of the car on the map. This is, of course, in actual production, if the card hair want to see the effect, the author here provides a train of thought, can build a ArrayList to include the whole line of electric information, and then constantly every 3 seconds to read the three points to map incoming component library SDK, reciprocating, so you can see the effect.

Code implementation

/ * * * a smooth move * @ param points * / private void translateAnima (LatLng [] points) {if (points = = null | | points. The length < = 0) return; If (point.length == 2 &&shelper.equaloFlatLNG (points[0], points[1])) return; if(carMarker ! = null) carMarker.remove(); CarMarker = mapView.getMap().addmarker (new MarkerOptions(points[0]).anchor(0.5f, 0.5 f.) icon (BitmapDescriptorFactory fromResource (R.m ipmap. Map_icon_driver)) / / set the property marker will follow the map rotation. The flat (true) / / marker Clockwise rotation. (false) Log.e("tag1234", ">>>>>startAnimation()"); // Car smooth movement core component class, Use com.tencent. Map: SDK-Utilities :1.0.6 to obtain MarkerTranslateAnimator mTranslateAnimator = new MarkerTranslateAnimator( // Implement the marker carMarker of this pan animation, // animation duration animaTime, // pan animation points, // whether marker will calculate and execute the rotation animation based on the points passed in, Marker direction will be consistent with the direction of movement true); mTranslateAnimator.startAnimation(); mTranslateAnimator.setFloatValuesListener(new MarkerTranslateAnimator.IAnimaFloatValuesListener() { @Override public Void floatValues(LatLng LatLng) {// eraseRoute(LatLng); }}); } private void eraseRoute(LatLng LatLng) {if(eraseThread == null) {eraseThread = new HandlerThread("car_erase_line"); eraseThread.start(); } if(eraseHandler == null ) { eraseHandler = new EraseHandler(eraseThread.getLooper()); } Message message = Message.obtain(); message.obj = latLng; message.what = ERASE_MSG; eraseHandler.sendMessage(message); } class EraseHandler extends Handler { public EraseHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { super.handleMessage(msg); try{ switch (msg.what){ case ERASE_MSG: LatLng latLng = (LatLng) (msg.obj); if(latLng ! = null && polyline ! = null) polyline.eraseTo(curEraseLatlng ! = null ? curEraseLatlng.getPointIndex() : 0, latLng); eraseHandler.removeMessages(ERASE_MSG); break; } }catch (Exception e){ Log.e(LOG_TAG, "erase handler handle message error:" + e.getMessage()); }}}Copy the code

If interested, you can take a look at the full implementation demo here: github.com/tencentmap-…

Final effect display

Author: Tencent Location Service

Link: my.oschina.net/u/4209404/b…

Source: Open Source China

Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.