1. AndroidManifest.xml

    1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    2. package="me.luzhuo.lib_map">
    3. <application>
    4. <!-- 修改 key -->
    5. <meta-data android:name="com.amap.api.v2.apikey" android:value="da0c71fcb0300fb776f3659f2a6488fb"/>
    6. </application>
    7. </manifest>

    1. 定位

    2. 2D地图

    3. 轨迹

    ```java public class MainActivity extends AppCompatActivity { private static final String TAG = MainActivity.class.getSimpleName(); public static final String TERMINAL_NAME = “666666”; // 终端名, 可使用用户id public static final int SERVICE_ID = 272075; // 后端创建 private TrackManager trackManager;

    // 如果想继续上报指定轨迹, 则指定轨迹值, 否则使用新值 private Long myTrackId = 2060L;

    @Override protected void onCreate(@Nullable Bundle savedInstanceState) {

    1. super.onCreate(savedInstanceState);
    2. setContentView(R.layout.activity_main);
  1. trackManager = new TrackManager(this, SERVICE_ID);
  2. trackManager.setOnTrackCallback(new OnTrackCallback() {
  3. @Override
  4. public void onStartTrack(long terminalId, long trackId) {
  5. if (myTrackId != null) trackManager.startGather(myTrackId);
  6. else trackManager.startGather(trackId);
  7. }
  8. @Override
  9. public void onStopTrack(long terminalId, long trackId) {
  10. if (myTrackId != null) Toast.makeText(MainActivity.this, "继续轨迹已停止记录: " + terminalId + " : " + trackId, Toast.LENGTH_SHORT).show();
  11. else Toast.makeText(MainActivity.this, "轨迹已停止记录: " + terminalId + " : " + trackId, Toast.LENGTH_SHORT).show();
  12. }
  13. @Override
  14. public void onStartGather(long terminalId, long trackId) {
  15. if (myTrackId != null) Log.e(TAG, "开始继续纪录轨迹: " + terminalId + " : " + trackId);
  16. else Log.e(TAG, "开始纪录轨迹: " + terminalId + " : " + trackId);
  17. }
  18. @Override
  19. public void onStopGather(long terminalId, long trackId) {
  20. trackManager.stopTrack(terminalId);
  21. }
  22. });
  23. }
  24. public void start_track(View view) {
  25. Permission.request(this, new PermissionCallback() {
  26. @Override
  27. public void onGranted() {
  28. trackManager.startTrack(TERMINAL_NAME);
  29. }
  30. }, Manifest.permission.ACCESS_FINE_LOCATION);
  31. }
  32. public void stop_track(View view) {
  33. trackManager.stopGather();
  34. }

} ```