preface
When using taxi-hailing software to take a taxi, we will be curious about the driver when driving the passenger, the passenger’s mobile phone is not in the navigation, then how to do it? Today we are going to uncover its mysteries
The preparatory work
To realize this function, Tencent Location Services Family Bucket is still required: Tencent Navigation SDK, Tencent Map SDK, Tencent Location SDK, and Tencent Company and ride SDK. To open the specific permissions, you need to go to the official website console of lbs.qq.com. To operate the specific permissions of SDK, you can contact Little Assistant for consultation (as shown in the figure below).
The specific implementation
Depend on libraries using the core map tools
//module relies on dependencies {// map library implementation 'com.tcent.map: tcent-map-vector-sdk :4.4.2' // map library Include car translation, point aggregation and other component functions, see the development guide for details. Must!! Implementation 'com.tcent.map: SDK-Utilities :1.0.6' // To locate the SDK, contact the implementation assistant on the website of Tencent Location Service Files ('libs/ tencentLocationSDK_v8.4.14_ra0311232_20200103_125837_release. aar') // Passenger side SDK, You can get the implementation files('libs/lspassenger_v2.0.1_04.03.aar') from the Tencent location service center official website contact little assistant implementation Files ('libs/lssupport_v2.0.1_04.03.aar') // Base library. You can contact the little assistant from the official website of Tencent location service center to get the implementation 'com. tcent.map: tcent-map-nav-surport :1.0.2.3'}
Flow chart display
According to the above flowchart, we know that in order to achieve the smooth movement of the car, it is necessary to constantly obtain the driver’s points and current route within the last few seconds. Specific process is when the driver started the passenger with show, show the SDK will pass the passenger with synchronous line and in the last few seconds of GPS point, continuous training in rotation so that we can show the car on the map and the smooth movement. 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 (points.length == 2 &&shelper. equaloFlatLNG (points[0], points[1])) return; if(carMarker ! = null) carMarker.remove(); CarMarker = MapView.getMap ().addMarker(new MarkerOptions(points[0]). 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 Wise counterclockwise!! Log.e("tag1234", ">>>>>startAnimation()"); // Trolley smooth movement core component class, MTranslateAnimator = new MarkerTranslateAnimator(com.tcent.map :sdk-utilities:1.0.6) // The animation duration is animaTime. // Points for the translation animation. // Whether the marker will calculate and execute the rotation animation based on the passed points. The direction of marker will be consistent with the moving direction true); mTranslateAnimator.startAnimation(); mTranslateAnimator.setFloatValuesListener(new MarkerTranslateAnimator.IAnimaFloatValuesListener() { @Override public Void floatValues(LatLng LatLng) {// Eraseroute (LatLng) eraseRoute eraseRoute(LatLng) eraseRoute; }}); } private void eraThread (latLNG latLNG) {if(eraThRead == null) {eraThRead = 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()); }}}
If interested in friends, you can see here the full implementation of demo:https://github.com/tencentmap…
The final display