AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.luzhuo.lib_map">
<application>
<!-- 修改 key -->
<meta-data android:name="com.amap.api.v2.apikey" android:value="da0c71fcb0300fb776f3659f2a6488fb"/>
</application>
</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) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
trackManager = new TrackManager(this, SERVICE_ID);
trackManager.setOnTrackCallback(new OnTrackCallback() {
@Override
public void onStartTrack(long terminalId, long trackId) {
if (myTrackId != null) trackManager.startGather(myTrackId);
else trackManager.startGather(trackId);
}
@Override
public void onStopTrack(long terminalId, long trackId) {
if (myTrackId != null) Toast.makeText(MainActivity.this, "继续轨迹已停止记录: " + terminalId + " : " + trackId, Toast.LENGTH_SHORT).show();
else Toast.makeText(MainActivity.this, "轨迹已停止记录: " + terminalId + " : " + trackId, Toast.LENGTH_SHORT).show();
}
@Override
public void onStartGather(long terminalId, long trackId) {
if (myTrackId != null) Log.e(TAG, "开始继续纪录轨迹: " + terminalId + " : " + trackId);
else Log.e(TAG, "开始纪录轨迹: " + terminalId + " : " + trackId);
}
@Override
public void onStopGather(long terminalId, long trackId) {
trackManager.stopTrack(terminalId);
}
});
}
public void start_track(View view) {
Permission.request(this, new PermissionCallback() {
@Override
public void onGranted() {
trackManager.startTrack(TERMINAL_NAME);
}
}, Manifest.permission.ACCESS_FINE_LOCATION);
}
public void stop_track(View view) {
trackManager.stopGather();
}
} ```