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

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

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

null
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

null
Click to add the following diagram :

null
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 :

<meta-data

android:name=&quot;com.amap.api.v2.apikey&quot;

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



null
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



mMapView.onCreate(savedInstanceState);

if (aMap == null) {

aMap = mMapView.getMap();

myLocationStyle = new MyLocationStyle();

myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);

//  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

myLocationStyle.strokeWidth(1.0f);

// Set the display positioning button   And you can click

UiSettings settings = aMap.getUiSettings();

// Set the location monitoring

aMap.setLocationSource(this);

//  Show positioning buttons

settings.setMyLocationButtonEnabled(true);

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

aMap.setMyLocationEnabled(true);

//  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

mlocationClient.setLocationListener(this);

// 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

mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);

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

mLocationOption.setNeedAddress(true);

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

mLocationOption.setOnceLocation(false);

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

mLocationOption.setWifiActiveScan(true);

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

mLocationOption.setMockEnable(false);

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

mLocationOption.setInterval(2000);

// Set the positioning parameters for the positioning client object

mlocationClient.setLocationOption(mLocationOption);

// Start positioning

mlocationClient.startLocation();

/**

  • Positioning callback
  • /

@Override

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

aMap.moveCamera(CameraUpdateFactory.zoomTo(18));

// 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

mListener.onLocationChanged(aMapLocation);

// 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

mListener.onLocationChanged(aMapLocation);

}

} 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.
https://en.cdmana.com/2022/131/202205111301205094.html

Random recommended