current position:Home>Android realizes Gaode map track playback

Android realizes Gaode map track playback

2022-05-15 05:13:26InfoQ

  • Show marked points
  • Points move smoothly
  • Add breathing points
  • Write at the end

[](() Write it at the front


This article is about the integration of Gaode map track playback and single / A summary of multipoint marking function . It is convenient to read it when you use it in the future , It's also convenient for you , Avoid stepping on the same pit as me

Welcome to correct , No joy, no spray. , Please be kind , thank you !!!

[](() Get ready


[](() Interpretation of official documents

First go [ Official website ](() Check the development guide to prepare the content required in the project .

[](() Create an :

The pointer of the head image position in the upper left corner crosses and appears as shown in the figure

Click application management -> My application , Here's the picture

After creating a new application in the figure above, enter the following interface

Click New... After the two steps above are completed , After the new application is created, the application you created will be displayed in my application , I use it test As a demonstration . After the new building is completed, as shown in the figure below

Click to add the following diagram :

Submit the content in the figure above after editing , Will be in the application list key display , I won't show it here .

The above content is obtained from the official documents key The content of . It's relatively simple .

[](() Map api introduce :

// location

implementation 'com.amap.api:location:5.1.0'

// Search for

implementation 'com.amap.api:search:7.3.0'

// Navigation

implementation 'com.amap.api:navi-3dmap:7.6.0_3dmap7.6.0'

[](() Add permissions

<uses-permission android:name=&quot;android.permission.INTERNET&quot; />

<uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; />

<uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; />

<uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; />

<uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; />

<uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot;/>

<uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;/>

<uses-permission android:name=&quot;android.permission.CHANGE_WIFI_STATE&quot;/>

<uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/>

<uses-permission android:name=&quot;android.permission.ACCESS_LOCATION_EXTRA_COMMANDS&quot;/>

<uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; />

<uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; />

<uses-permission android:name=&quot;android.permission.CHANGE_WIFI_STATE&quot; />

<uses-permission android:name=&quot;android.permission.INTERNET&quot; />

<uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; />

<uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; />

And in AndroidManifest.xml Of application Add the following code to :



android:value=&quot; Create your own... In the application key&quot; />

<service android:name=&quot;com.amap.api.location.APSService&quot; />

Here the preparatory work is done . Let me show you the last renderings .

[](() Effect display

I just added a little breathing effect this morning , So the display effect is not reflected above , However, this function is not the focus of this project

[](() Process realization


[](() Map initialization


if (aMap == null) {

aMap = mMapView.getMap();

myLocationStyle = new MyLocationStyle();


//  Set the border color of the circle

myLocationStyle.strokeColor(Color.argb(50, 30, 150, 180));

//  Set the fill color of the circle

myLocationStyle.radiusFillColor(Color.argb(50, 30, 150, 180));

//  Set the border thickness of the circle


// Set the display positioning button   And you can click

UiSettings settings = aMap.getUiSettings();

// Set the location monitoring


//  Show positioning buttons


// The positioning layer is displayed and can trigger positioning , The default is flase


//  location 、 And move the perspective to the center of the map , The anchor point rotates in the direction of the equipment , And will follow the device .


[](() location

// Initialize positioning

mlocationClient = new AMapLocationClient(getApplicationContext());

// Set location callback listening


// Initialize positioning parameters

mLocationOption = new AMapLocationClientOption();

// Set the positioning mode to Hight_Accuracy High precision mode ,Battery_Saving Low power consumption mode ,Device_Sensors Is device only mode


// Set whether to return address information ( Default return address information )


// Set whether to locate only once , The default is false


// Set whether to force refresh WIFI, The default is forced refresh


// Sets whether analog locations are allowed , The default is false, Analog locations are not allowed


// Set the positioning interval , Unit millisecond , The default is 2000ms


// Set the positioning parameters for the positioning client object


// Start positioning



  • Positioning callback
  • /


public void onLocationChanged(AMapLocation aMapLocation) {

if (mListener != null && aMapLocation != null) {

if (aMapLocation != null && aMapLocation.getErrorCode() == 0) {

// Callback information after successful positioning , Set related messages

aMapLocation.getLocationType();// Get the source of the current positioning result , Such as network positioning results , See the official positioning type table for details

aMapLocation.getLatitude();// Get latitude

aMapLocation.getLongitude();// Get longitude

aMapLocation.getAccuracy();// Get accuracy information

SimpleDateFormat df = new SimpleDateFormat(&quot;yyyy-MM-dd HH:mm:ss&quot;);

Date date = new Date(aMapLocation.getTime());

df.format(date);// Location time

aMapLocation.getAddress();// Address , If option Set in isNeedAddress by false, There is no such result , There will be address information in the network location results ,GPS Location does not return address information .

aMapLocation.getCountry();// National Information

aMapLocation.getProvince();// Save information

aMapLocation.getCity();// City Information

aMapLocation.getDistrict();// City Information

aMapLocation.getStreet();// Street information

aMapLocation.getStreetNum();// Street number information

aMapLocation.getCityCode();// City Code

aMapLocation.getAdCode();// Area code

//  If the flag bit is not set , When you drag the map again , It keeps moving the map to its current location

if (isFirstLoc) {

// Set zoom level


// Move the map to the anchor point

aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude())));

// Click the locate button   It can move the center of the map to the positioning point


// Add pushpin

// aMap.addMarker(getMarkerOptions(amapLocation));

// Get location information

StringBuffer buffer = new StringBuffer();

buffer.append(aMapLocation.getCountry() + &quot;&quot;

  • aMapLocation.getProvince() + &quot;&quot;
  • aMapLocation.getCity() + &quot;&quot;
  • aMapLocation.getProvince() + &quot;&quot;
  • aMapLocation.getDistrict() + &quot;&quot;
  • aMapLocation.getStreet() + &quot;&quot;
  • aMapLocation.getStreetNum());

Toast.makeText(getApplicationContext(), buffer.toString(), Toast.LENGTH_LONG).show();

isFirstLoc = false;

//  Display system small blue dot



} else {

Log.e(&quot;AmapError&quot;, &quot;location Error, ErrCode:&quot;

  • aMapLocation.getErrorCode() + &quot;, errInfo:&quot;
  • aMapLocation.getErrorInfo());

Toast.makeText(getApplicationContext(), &quot; seek failed &quot;, Toast.LENGTH_LONG).show();

copyright notice
author[InfoQ],Please bring the original link to reprint, thank you.

Random recommended