├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── apk ├── 1478158919.png └── path_record.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── amap │ │ └── com │ │ └── android_path_record │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── amap │ │ │ └── com │ │ │ ├── android_path_record │ │ │ ├── MainActivity.java │ │ │ ├── RecordActivity.java │ │ │ ├── RecordAdapter.java │ │ │ └── RecordShowActivity.java │ │ │ ├── database │ │ │ └── DbAdapter.java │ │ │ ├── record │ │ │ └── PathRecord.java │ │ │ ├── recorduitl │ │ │ └── Util.java │ │ │ ├── test │ │ │ └── EmulatorService.java │ │ │ └── tracereplay │ │ │ └── TraceRePlay.java │ └── res │ │ ├── drawable │ │ ├── back_btn_image.png │ │ ├── end.png │ │ ├── grasp_flag.png │ │ ├── grasp_trace_line.png │ │ ├── point.png │ │ ├── point5.png │ │ ├── start.png │ │ ├── title_background.9.png │ │ └── walk.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── basicmap_activity.xml │ │ ├── recorddisplay_activity.xml │ │ ├── recorditem.xml │ │ └── recordlist.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── amap │ └── com │ └── android_path_record │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # android-path-record 2 | 轨迹回放和轨迹纠偏 3 | 4 | 本工程为基于高德地图Android SDK进行封装,实现了定位轨迹记录并回放的功能 5 | ## 前述 ## 6 | - [高德官网申请Key](http://lbs.amap.com/dev/#/). 7 | - 阅读[参考手册](http://a.amap.com/lbs/static/unzip/Android_Map_Doc/index.html). 8 | - 工程基于Android 3D地图SDK实现 9 | 10 | ## 功能描述 ## 11 | 基于3D地图SDK,可以记录定位点信息并实时绘制轨迹,记录过程中每隔30个点进行轨迹纠偏(将定位点抓到道路上),停止记录时对原始定位轨迹进行保存。可以在轨迹记录中查看已保存轨迹并回放。 12 | 13 | ## 扫一扫安装## 14 | ![Screenshot]( https://raw.githubusercontent.com/amap-demo/android-path-record/master/apk/1478158919.png) 15 | 16 | ## 使用方法## 17 | ###1:配置搭建AndroidSDK工程### 18 | - [Android Studio工程搭建方法](http://lbs.amap.com/api/android-sdk/guide/creat-project/android-studio-creat-project/#add-jars). 19 | - [通过maven库引入SDK方法](http://lbsbbs.amap.com/forum.php?mod=viewthread&tid=18786). 20 | 21 | -------------------------------------------------------------------------------- /apk/1478158919.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/apk/1478158919.png -------------------------------------------------------------------------------- /apk/path_record.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/apk/path_record.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | defaultConfig { 7 | applicationId "amap.com.android_path_record" 8 | minSdkVersion 8 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:23.4.0' 28 | compile 'com.amap.api:3dmap:latest.integration' 29 | compile 'com.amap.api:location:latest.integration' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Software\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/amap/com/android_path_record/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package amap.com.android_path_record; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("amap.com.android_path_record", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/android_path_record/MainActivity.java: -------------------------------------------------------------------------------- 1 | package amap.com.android_path_record; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.graphics.Color; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.view.View.OnClickListener; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | import android.widget.ToggleButton; 14 | 15 | import com.amap.api.location.AMapLocation; 16 | import com.amap.api.location.AMapLocationClient; 17 | import com.amap.api.location.AMapLocationClientOption; 18 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; 19 | import com.amap.api.location.AMapLocationListener; 20 | import com.amap.api.maps.AMap; 21 | import com.amap.api.maps.AMapUtils; 22 | import com.amap.api.maps.CameraUpdateFactory; 23 | import com.amap.api.maps.LocationSource; 24 | import com.amap.api.maps.MapView; 25 | import com.amap.api.maps.model.BitmapDescriptorFactory; 26 | import com.amap.api.maps.model.LatLng; 27 | import com.amap.api.maps.model.Marker; 28 | import com.amap.api.maps.model.MarkerOptions; 29 | import com.amap.api.maps.model.Polyline; 30 | import com.amap.api.maps.model.PolylineOptions; 31 | import com.amap.api.trace.LBSTraceClient; 32 | import com.amap.api.trace.TraceListener; 33 | import com.amap.api.trace.TraceLocation; 34 | import com.amap.api.trace.TraceOverlay; 35 | 36 | import java.text.DecimalFormat; 37 | import java.text.SimpleDateFormat; 38 | import java.util.ArrayList; 39 | import java.util.Date; 40 | import java.util.List; 41 | 42 | import amap.com.database.DbAdapter; 43 | import amap.com.record.PathRecord; 44 | import amap.com.recorduitl.Util; 45 | 46 | 47 | public class MainActivity extends Activity implements LocationSource, 48 | AMapLocationListener, TraceListener { 49 | private final static int CALLTRACE = 0; 50 | private MapView mMapView; 51 | private AMap mAMap; 52 | private OnLocationChangedListener mListener; 53 | private AMapLocationClient mLocationClient; 54 | private AMapLocationClientOption mLocationOption; 55 | private PolylineOptions mPolyoptions, tracePolytion; 56 | private Polyline mpolyline; 57 | private PathRecord record; 58 | private long mStartTime; 59 | private long mEndTime; 60 | private ToggleButton btn; 61 | private DbAdapter DbHepler; 62 | private List mTracelocationlist = new ArrayList(); 63 | private List mOverlayList = new ArrayList(); 64 | private List recordList = new ArrayList(); 65 | private int tracesize = 30; 66 | private int mDistance = 0; 67 | private TraceOverlay mTraceoverlay; 68 | private TextView mResultShow; 69 | private Marker mlocMarker; 70 | 71 | @Override 72 | protected void onCreate(Bundle savedInstanceState) { 73 | super.onCreate(savedInstanceState); 74 | setContentView(R.layout.basicmap_activity); 75 | mMapView = (MapView) findViewById(R.id.map); 76 | mMapView.onCreate(savedInstanceState);// 此方法必须重写 77 | init(); 78 | initpolyline(); 79 | } 80 | 81 | /** 82 | * 初始化AMap对象 83 | */ 84 | private void init() { 85 | if (mAMap == null) { 86 | mAMap = mMapView.getMap(); 87 | setUpMap(); 88 | } 89 | btn = (ToggleButton) findViewById(R.id.locationbtn); 90 | btn.setOnClickListener(new OnClickListener() { 91 | @Override 92 | public void onClick(View v) { 93 | if (btn.isChecked()) { 94 | mAMap.clear(true); 95 | if (record != null) { 96 | record = null; 97 | } 98 | record = new PathRecord(); 99 | mStartTime = System.currentTimeMillis(); 100 | record.setDate(getcueDate(mStartTime)); 101 | mResultShow.setText("总距离"); 102 | } else { 103 | mEndTime = System.currentTimeMillis(); 104 | mOverlayList.add(mTraceoverlay); 105 | DecimalFormat decimalFormat = new DecimalFormat("0.0"); 106 | mResultShow.setText( 107 | decimalFormat.format(getTotalDistance() / 1000d) + "KM"); 108 | LBSTraceClient mTraceClient = new LBSTraceClient(getApplicationContext()); 109 | mTraceClient.queryProcessedTrace(2, Util.parseTraceLocationList(record.getPathline()) , LBSTraceClient.TYPE_AMAP, MainActivity.this); 110 | saveRecord(record.getPathline(), record.getDate()); 111 | } 112 | } 113 | }); 114 | mResultShow = (TextView) findViewById(R.id.show_all_dis); 115 | 116 | mTraceoverlay = new TraceOverlay(mAMap); 117 | } 118 | 119 | protected void saveRecord(List list, String time) { 120 | if (list != null && list.size() > 0) { 121 | DbHepler = new DbAdapter(this); 122 | DbHepler.open(); 123 | String duration = getDuration(); 124 | float distance = getDistance(list); 125 | String average = getAverage(distance); 126 | String pathlineSring = getPathLineString(list); 127 | AMapLocation firstLocaiton = list.get(0); 128 | AMapLocation lastLocaiton = list.get(list.size() - 1); 129 | String stratpoint = amapLocationToString(firstLocaiton); 130 | String endpoint = amapLocationToString(lastLocaiton); 131 | DbHepler.createrecord(String.valueOf(distance), duration, average, 132 | pathlineSring, stratpoint, endpoint, time); 133 | DbHepler.close(); 134 | } else { 135 | Toast.makeText(MainActivity.this, "没有记录到路径", Toast.LENGTH_SHORT) 136 | .show(); 137 | } 138 | } 139 | 140 | private String getDuration() { 141 | return String.valueOf((mEndTime - mStartTime) / 1000f); 142 | } 143 | 144 | private String getAverage(float distance) { 145 | return String.valueOf(distance / (float) (mEndTime - mStartTime)); 146 | } 147 | 148 | private float getDistance(List list) { 149 | float distance = 0; 150 | if (list == null || list.size() == 0) { 151 | return distance; 152 | } 153 | for (int i = 0; i < list.size() - 1; i++) { 154 | AMapLocation firstpoint = list.get(i); 155 | AMapLocation secondpoint = list.get(i + 1); 156 | LatLng firstLatLng = new LatLng(firstpoint.getLatitude(), 157 | firstpoint.getLongitude()); 158 | LatLng secondLatLng = new LatLng(secondpoint.getLatitude(), 159 | secondpoint.getLongitude()); 160 | double betweenDis = AMapUtils.calculateLineDistance(firstLatLng, 161 | secondLatLng); 162 | distance = (float) (distance + betweenDis); 163 | } 164 | return distance; 165 | } 166 | 167 | private String getPathLineString(List list) { 168 | if (list == null || list.size() == 0) { 169 | return ""; 170 | } 171 | StringBuffer pathline = new StringBuffer(); 172 | for (int i = 0; i < list.size(); i++) { 173 | AMapLocation location = list.get(i); 174 | String locString = amapLocationToString(location); 175 | pathline.append(locString).append(";"); 176 | } 177 | String pathLineString = pathline.toString(); 178 | pathLineString = pathLineString.substring(0, 179 | pathLineString.length() - 1); 180 | return pathLineString; 181 | } 182 | 183 | private String amapLocationToString(AMapLocation location) { 184 | StringBuffer locString = new StringBuffer(); 185 | locString.append(location.getLatitude()).append(","); 186 | locString.append(location.getLongitude()).append(","); 187 | locString.append(location.getProvider()).append(","); 188 | locString.append(location.getTime()).append(","); 189 | locString.append(location.getSpeed()).append(","); 190 | locString.append(location.getBearing()); 191 | return locString.toString(); 192 | } 193 | 194 | private void initpolyline() { 195 | mPolyoptions = new PolylineOptions(); 196 | mPolyoptions.width(10f); 197 | mPolyoptions.color(Color.GRAY); 198 | tracePolytion = new PolylineOptions(); 199 | tracePolytion.width(40); 200 | tracePolytion.setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.grasp_trace_line)); 201 | } 202 | 203 | /** 204 | * 设置一些amap的属性 205 | */ 206 | private void setUpMap() { 207 | mAMap.setLocationSource(this);// 设置定位监听 208 | mAMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示 209 | mAMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false 210 | // 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种 211 | mAMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE); 212 | } 213 | 214 | /** 215 | * 方法必须重写 216 | */ 217 | @Override 218 | protected void onResume() { 219 | super.onResume(); 220 | mMapView.onResume(); 221 | } 222 | 223 | /** 224 | * 方法必须重写 225 | */ 226 | @Override 227 | protected void onPause() { 228 | super.onPause(); 229 | mMapView.onPause(); 230 | } 231 | 232 | /** 233 | * 方法必须重写 234 | */ 235 | @Override 236 | protected void onSaveInstanceState(Bundle outState) { 237 | super.onSaveInstanceState(outState); 238 | mMapView.onSaveInstanceState(outState); 239 | } 240 | 241 | /** 242 | * 方法必须重写 243 | */ 244 | @Override 245 | protected void onDestroy() { 246 | super.onDestroy(); 247 | mMapView.onDestroy(); 248 | } 249 | 250 | @Override 251 | public void activate(OnLocationChangedListener listener) { 252 | mListener = listener; 253 | startlocation(); 254 | } 255 | 256 | @Override 257 | public void deactivate() { 258 | mListener = null; 259 | if (mLocationClient != null) { 260 | mLocationClient.stopLocation(); 261 | mLocationClient.onDestroy(); 262 | 263 | } 264 | mLocationClient = null; 265 | } 266 | 267 | /** 268 | * 定位结果回调 269 | * @param amapLocation 位置信息类 270 | */ 271 | @Override 272 | public void onLocationChanged(AMapLocation amapLocation) { 273 | if (mListener != null && amapLocation != null) { 274 | if (amapLocation != null && amapLocation.getErrorCode() == 0) { 275 | mListener.onLocationChanged(amapLocation);// 显示系统小蓝点 276 | LatLng mylocation = new LatLng(amapLocation.getLatitude(), 277 | amapLocation.getLongitude()); 278 | mAMap.moveCamera(CameraUpdateFactory.changeLatLng(mylocation)); 279 | if (btn.isChecked()) { 280 | record.addpoint(amapLocation); 281 | mPolyoptions.add(mylocation); 282 | mTracelocationlist.add(Util.parseTraceLocation(amapLocation)); 283 | redrawline(); 284 | if (mTracelocationlist.size() > tracesize - 1) { 285 | trace(); 286 | } 287 | } 288 | } else { 289 | String errText = "定位失败," + amapLocation.getErrorCode() + ": " 290 | + amapLocation.getErrorInfo(); 291 | Log.e("AmapErr", errText); 292 | } 293 | } 294 | } 295 | 296 | /** 297 | * 开始定位。 298 | */ 299 | private void startlocation() { 300 | if (mLocationClient == null) { 301 | mLocationClient = new AMapLocationClient(this); 302 | mLocationOption = new AMapLocationClientOption(); 303 | // 设置定位监听 304 | mLocationClient.setLocationListener(this); 305 | // 设置为高精度定位模式 306 | mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy); 307 | 308 | mLocationOption.setInterval(2000); 309 | 310 | // 设置定位参数 311 | mLocationClient.setLocationOption(mLocationOption); 312 | // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗, 313 | // 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求 314 | // 在定位结束后,在合适的生命周期调用onDestroy()方法 315 | // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除 316 | mLocationClient.startLocation(); 317 | 318 | } 319 | } 320 | 321 | /** 322 | * 实时轨迹画线 323 | */ 324 | private void redrawline() { 325 | if (mPolyoptions.getPoints().size() > 1) { 326 | if (mpolyline != null) { 327 | mpolyline.setPoints(mPolyoptions.getPoints()); 328 | } else { 329 | mpolyline = mAMap.addPolyline(mPolyoptions); 330 | } 331 | } 332 | // if (mpolyline != null) { 333 | // mpolyline.remove(); 334 | // } 335 | // mPolyoptions.visible(true); 336 | // mpolyline = mAMap.addPolyline(mPolyoptions); 337 | // PolylineOptions newpoly = new PolylineOptions(); 338 | // mpolyline = mAMap.addPolyline(newpoly.addAll(mPolyoptions.getPoints())); 339 | // } 340 | } 341 | 342 | @SuppressLint("SimpleDateFormat") 343 | private String getcueDate(long time) { 344 | SimpleDateFormat formatter = new SimpleDateFormat( 345 | "yyyy-MM-dd HH:mm:ss "); 346 | Date curDate = new Date(time); 347 | String date = formatter.format(curDate); 348 | return date; 349 | } 350 | 351 | public void record(View view) { 352 | Intent intent = new Intent(MainActivity.this, RecordActivity.class); 353 | startActivity(intent); 354 | } 355 | 356 | private void trace() { 357 | List locationList = new ArrayList<>(mTracelocationlist); 358 | LBSTraceClient mTraceClient = new LBSTraceClient(getApplicationContext()); 359 | mTraceClient.queryProcessedTrace(1, locationList, LBSTraceClient.TYPE_AMAP, this); 360 | TraceLocation lastlocation = mTracelocationlist.get(mTracelocationlist.size()-1); 361 | mTracelocationlist.clear(); 362 | mTracelocationlist.add(lastlocation); 363 | } 364 | 365 | /** 366 | * 轨迹纠偏失败回调。 367 | * @param i 368 | * @param s 369 | */ 370 | @Override 371 | public void onRequestFailed(int i, String s) { 372 | mOverlayList.add(mTraceoverlay); 373 | mTraceoverlay = new TraceOverlay(mAMap); 374 | } 375 | 376 | @Override 377 | public void onTraceProcessing(int i, int i1, List list) { 378 | 379 | } 380 | 381 | /** 382 | * 轨迹纠偏成功回调。 383 | * @param lineID 纠偏的线路ID 384 | * @param linepoints 纠偏结果 385 | * @param distance 总距离 386 | * @param waitingtime 等待时间 387 | */ 388 | @Override 389 | public void onFinished(int lineID, List linepoints, int distance, int waitingtime) { 390 | if (lineID == 1) { 391 | if (linepoints != null && linepoints.size()>0) { 392 | mTraceoverlay.add(linepoints); 393 | mDistance += distance; 394 | mTraceoverlay.setDistance(mTraceoverlay.getDistance()+distance); 395 | if (mlocMarker == null) { 396 | mlocMarker = mAMap.addMarker(new MarkerOptions().position(linepoints.get(linepoints.size() - 1)) 397 | .icon(BitmapDescriptorFactory 398 | .fromResource(R.drawable.point)) 399 | .title("距离:" + mDistance+"米")); 400 | mlocMarker.showInfoWindow(); 401 | } else { 402 | mlocMarker.setTitle("距离:" + mDistance+"米"); 403 | Toast.makeText(MainActivity.this, "距离"+mDistance, Toast.LENGTH_SHORT).show(); 404 | mlocMarker.setPosition(linepoints.get(linepoints.size() - 1)); 405 | mlocMarker.showInfoWindow(); 406 | } 407 | } 408 | } else if (lineID == 2) { 409 | if (linepoints != null && linepoints.size()>0) { 410 | mAMap.addPolyline(new PolylineOptions() 411 | .color(Color.RED) 412 | .width(40).addAll(linepoints)); 413 | } 414 | } 415 | 416 | } 417 | 418 | /** 419 | * 最后获取总距离 420 | * @return 421 | */ 422 | private int getTotalDistance() { 423 | int distance = 0; 424 | for (TraceOverlay to : mOverlayList) { 425 | distance = distance + to.getDistance(); 426 | } 427 | return distance; 428 | } 429 | } 430 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/android_path_record/RecordActivity.java: -------------------------------------------------------------------------------- 1 | package amap.com.android_path_record; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.AdapterView.OnItemClickListener; 9 | import android.widget.ListView; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import amap.com.database.DbAdapter; 15 | import amap.com.record.PathRecord; 16 | 17 | /** 18 | * 所有轨迹list展示activity 19 | * 20 | */ 21 | public class RecordActivity extends Activity implements OnItemClickListener { 22 | 23 | private RecordAdapter mAdapter; 24 | private ListView mAllRecordListView; 25 | private DbAdapter mDataBaseHelper; 26 | private List mAllRecord = new ArrayList(); 27 | public static final String RECORD_ID = "record_id"; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.recordlist); 33 | mAllRecordListView = (ListView) findViewById(R.id.recordlist); 34 | mDataBaseHelper = new DbAdapter(this); 35 | mDataBaseHelper.open(); 36 | searchAllRecordFromDB(); 37 | mAdapter = new RecordAdapter(this, mAllRecord); 38 | mAllRecordListView.setAdapter(mAdapter); 39 | mAllRecordListView.setOnItemClickListener(this); 40 | } 41 | 42 | private void searchAllRecordFromDB() { 43 | mAllRecord = mDataBaseHelper.queryRecordAll(); 44 | } 45 | 46 | public void onBackClick(View view) { 47 | this.finish(); 48 | } 49 | 50 | @Override 51 | public void onItemClick(AdapterView parent, View view, int position, 52 | long id) { 53 | PathRecord recorditem = (PathRecord) parent.getAdapter().getItem( 54 | position); 55 | Intent intent = new Intent(RecordActivity.this, 56 | RecordShowActivity.class); 57 | intent.putExtra(RECORD_ID, recorditem.getId()); 58 | startActivity(intent); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/android_path_record/RecordAdapter.java: -------------------------------------------------------------------------------- 1 | package amap.com.android_path_record; 2 | 3 | import java.util.List; 4 | 5 | import android.content.Context; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.TextView; 10 | 11 | 12 | import amap.com.record.PathRecord; 13 | 14 | public class RecordAdapter extends BaseAdapter { 15 | 16 | private Context mContext; 17 | private List mRecordList; 18 | 19 | public RecordAdapter(Context context, List list) { 20 | this.mContext = context; 21 | this.mRecordList = list; 22 | } 23 | 24 | @Override 25 | public int getCount() { 26 | return mRecordList.size(); 27 | } 28 | 29 | @Override 30 | public Object getItem(int position) { 31 | return mRecordList.get(position); 32 | } 33 | 34 | @Override 35 | public long getItemId(int position) { 36 | return position; 37 | } 38 | 39 | @Override 40 | public View getView(int position, View convertView, ViewGroup parent) { 41 | ViewHolder holder; 42 | if (convertView == null) { 43 | holder = new ViewHolder(); 44 | convertView = View.inflate(mContext, R.layout.recorditem, null); 45 | holder.date = (TextView) convertView.findViewById(R.id.date); 46 | holder.record = (TextView) convertView.findViewById(R.id.record); 47 | 48 | convertView.setTag(holder); 49 | } else { 50 | holder = (ViewHolder) convertView.getTag(); 51 | } 52 | 53 | PathRecord item = mRecordList.get(position); 54 | holder.date.setText(item.getDate()); 55 | holder.record.setText(item.toString()); 56 | return convertView; 57 | } 58 | 59 | private class ViewHolder { 60 | TextView date; 61 | TextView record; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/android_path_record/RecordShowActivity.java: -------------------------------------------------------------------------------- 1 | package amap.com.android_path_record; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.graphics.BitmapFactory; 7 | import android.graphics.Color; 8 | import android.os.Bundle; 9 | import android.os.Handler; 10 | import android.os.Message; 11 | import android.util.Log; 12 | import android.view.View; 13 | import android.view.View.OnClickListener; 14 | import android.widget.RadioButton; 15 | import android.widget.Toast; 16 | import android.widget.ToggleButton; 17 | 18 | import com.amap.api.location.AMapLocation; 19 | import com.amap.api.maps.AMap; 20 | import com.amap.api.maps.AMap.OnMapLoadedListener; 21 | import com.amap.api.maps.CameraUpdateFactory; 22 | import com.amap.api.maps.MapView; 23 | import com.amap.api.maps.model.BitmapDescriptorFactory; 24 | import com.amap.api.maps.model.LatLng; 25 | import com.amap.api.maps.model.LatLngBounds; 26 | import com.amap.api.maps.model.Marker; 27 | import com.amap.api.maps.model.MarkerOptions; 28 | import com.amap.api.maps.model.Polyline; 29 | import com.amap.api.maps.model.PolylineOptions; 30 | import com.amap.api.trace.LBSTraceClient; 31 | import com.amap.api.trace.TraceListener; 32 | import com.amap.api.trace.TraceLocation; 33 | import java.util.List; 34 | import java.util.concurrent.ExecutorService; 35 | import java.util.concurrent.Executors; 36 | 37 | import amap.com.database.DbAdapter; 38 | import amap.com.record.PathRecord; 39 | import amap.com.recorduitl.Util; 40 | import amap.com.tracereplay.TraceRePlay; 41 | 42 | 43 | /** 44 | * 实现轨迹回放、纠偏后轨迹回放 45 | * 46 | */ 47 | public class RecordShowActivity extends Activity implements 48 | OnMapLoadedListener, TraceListener, OnClickListener { 49 | private final static int AMAP_LOADED = 2; 50 | 51 | private RadioButton mOriginRadioButton, mGraspRadioButton; 52 | private ToggleButton mDisplaybtn; 53 | 54 | private MapView mMapView; 55 | private AMap mAMap; 56 | private Marker mOriginStartMarker, mOriginEndMarker, mOriginRoleMarker; 57 | private Marker mGraspStartMarker, mGraspEndMarker, mGraspRoleMarker; 58 | private Polyline mOriginPolyline, mGraspPolyline; 59 | 60 | private int mRecordItemId; 61 | private List mOriginLatLngList; 62 | private List mGraspLatLngList; 63 | private boolean mGraspChecked = false; 64 | private boolean mOriginChecked = true; 65 | private ExecutorService mThreadPool; 66 | private TraceRePlay mRePlay; 67 | 68 | @Override 69 | protected void onCreate(Bundle savedInstanceState) { 70 | super.onCreate(savedInstanceState); 71 | setContentView(R.layout.recorddisplay_activity); 72 | mMapView = (MapView) findViewById(R.id.map); 73 | mMapView.onCreate(savedInstanceState);// 此方法必须重写 74 | mGraspRadioButton = (RadioButton) findViewById(R.id.record_show_activity_grasp_radio_button); 75 | mOriginRadioButton = (RadioButton) findViewById(R.id.record_show_activity_origin_radio_button); 76 | mOriginRadioButton.setOnClickListener(this); 77 | mGraspRadioButton.setOnClickListener(this); 78 | mDisplaybtn = (ToggleButton) findViewById(R.id.displaybtn); 79 | mDisplaybtn.setOnClickListener(this); 80 | Intent recordIntent = getIntent(); 81 | int threadPoolSize = Runtime.getRuntime().availableProcessors() * 2 + 3; 82 | mThreadPool = Executors.newFixedThreadPool(threadPoolSize); 83 | if (recordIntent != null) { 84 | mRecordItemId = recordIntent.getIntExtra(RecordActivity.RECORD_ID, 85 | -1); 86 | } 87 | initMap(); 88 | } 89 | 90 | private void initMap() { 91 | if (mAMap == null) { 92 | mAMap = mMapView.getMap(); 93 | mAMap.setOnMapLoadedListener(this); 94 | } 95 | } 96 | 97 | 98 | private void startMove() { 99 | if(mRePlay !=null){ 100 | mRePlay.stopTrace(); 101 | } 102 | if (mOriginChecked) { 103 | mRePlay = rePlayTrace(mOriginLatLngList, mOriginRoleMarker); 104 | } else if (mGraspChecked) { 105 | mRePlay = rePlayTrace(mGraspLatLngList, mGraspRoleMarker); 106 | } 107 | } 108 | 109 | /** 110 | * 轨迹回放方法 111 | */ 112 | private TraceRePlay rePlayTrace(List list, final Marker updateMarker) { 113 | TraceRePlay replay = new TraceRePlay(list, 100, 114 | new TraceRePlay.TraceRePlayListener() { 115 | 116 | @Override 117 | public void onTraceUpdating(LatLng latLng) { 118 | if (updateMarker != null) { 119 | updateMarker.setPosition(latLng); // 更新小人实现轨迹回放 120 | } 121 | } 122 | 123 | @Override 124 | public void onTraceUpdateFinish() { 125 | mDisplaybtn.setChecked(false); 126 | mDisplaybtn.setClickable(true); 127 | } 128 | }); 129 | mThreadPool.execute(replay); 130 | return replay; 131 | } 132 | 133 | /** 134 | * 将纠偏后轨迹小人设置到起点 135 | */ 136 | private void resetGraspRole() { 137 | if (mGraspLatLngList == null) { 138 | return; 139 | } 140 | LatLng startLatLng = mGraspLatLngList.get(0); 141 | if (mGraspRoleMarker != null) { 142 | mGraspRoleMarker.setPosition(startLatLng); 143 | } 144 | } 145 | 146 | /** 147 | * 将原始轨迹小人设置到起点 148 | */ 149 | private void resetOriginRole() { 150 | if (mOriginLatLngList == null) { 151 | return; 152 | } 153 | LatLng startLatLng = mOriginLatLngList.get(0); 154 | if (mOriginRoleMarker != null) { 155 | mOriginRoleMarker.setPosition(startLatLng); 156 | } 157 | } 158 | 159 | @SuppressLint("HandlerLeak") 160 | private Handler handler = new Handler() { 161 | 162 | @Override 163 | public void handleMessage(Message msg) { 164 | super.handleMessage(msg); 165 | switch (msg.what) { 166 | case AMAP_LOADED: 167 | setupRecord(); 168 | break; 169 | default: 170 | break; 171 | } 172 | } 173 | 174 | }; 175 | 176 | public void onBackClick(View view) { 177 | this.finish(); 178 | if (mThreadPool != null) { 179 | mThreadPool.shutdownNow(); 180 | } 181 | } 182 | 183 | public void onDestroy() { 184 | super.onDestroy(); 185 | if (mThreadPool != null) { 186 | mThreadPool.shutdownNow(); 187 | } 188 | } 189 | 190 | private LatLngBounds getBounds() { 191 | LatLngBounds.Builder b = LatLngBounds.builder(); 192 | if (mOriginLatLngList == null) { 193 | return b.build(); 194 | } 195 | for (int i = 0; i < mOriginLatLngList.size(); i++) { 196 | b.include(mOriginLatLngList.get(i)); 197 | } 198 | return b.build(); 199 | 200 | } 201 | 202 | /** 203 | * 轨迹数据初始化 204 | * 205 | */ 206 | private void setupRecord() { 207 | // 轨迹纠偏初始化 208 | LBSTraceClient mTraceClient = new LBSTraceClient( 209 | getApplicationContext()); 210 | DbAdapter dbhelper = new DbAdapter(this.getApplicationContext()); 211 | dbhelper.open(); 212 | PathRecord mRecord = dbhelper.queryRecordById(mRecordItemId); 213 | dbhelper.close(); 214 | if (mRecord != null) { 215 | List recordList = mRecord.getPathline(); 216 | AMapLocation startLoc = mRecord.getStartpoint(); 217 | AMapLocation endLoc = mRecord.getEndpoint(); 218 | if (recordList == null || startLoc == null || endLoc == null) { 219 | return; 220 | } 221 | LatLng startLatLng = new LatLng(startLoc.getLatitude(), 222 | startLoc.getLongitude()); 223 | LatLng endLatLng = new LatLng(endLoc.getLatitude(), 224 | endLoc.getLongitude()); 225 | mOriginLatLngList = Util.parseLatLngList(recordList); 226 | addOriginTrace(startLatLng, endLatLng, mOriginLatLngList); 227 | 228 | List mGraspTraceLocationList = Util 229 | .parseTraceLocationList(recordList); 230 | // 调用轨迹纠偏,将mGraspTraceLocationList进行轨迹纠偏处理 231 | mTraceClient.queryProcessedTrace(1, mGraspTraceLocationList, 232 | LBSTraceClient.TYPE_AMAP, this); 233 | } else { 234 | } 235 | 236 | } 237 | 238 | /** 239 | * 地图上添加原始轨迹线路及起终点、轨迹动画小人 240 | * 241 | * @param startPoint 242 | * @param endPoint 243 | * @param originList 244 | */ 245 | private void addOriginTrace(LatLng startPoint, LatLng endPoint, 246 | List originList) { 247 | mOriginPolyline = mAMap.addPolyline(new PolylineOptions().color( 248 | Color.BLUE).addAll(originList)); 249 | mOriginStartMarker = mAMap.addMarker(new MarkerOptions().position( 250 | startPoint).icon( 251 | BitmapDescriptorFactory.fromResource(R.drawable.start))); 252 | mOriginEndMarker = mAMap.addMarker(new MarkerOptions().position( 253 | endPoint).icon( 254 | BitmapDescriptorFactory.fromResource(R.drawable.end))); 255 | 256 | try { 257 | mAMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getBounds(), 258 | 50)); 259 | } catch (Exception e) { 260 | e.printStackTrace(); 261 | } 262 | 263 | mOriginRoleMarker = mAMap.addMarker(new MarkerOptions().position( 264 | startPoint).icon( 265 | BitmapDescriptorFactory.fromBitmap(BitmapFactory 266 | .decodeResource(getResources(), R.drawable.walk)))); 267 | } 268 | 269 | /** 270 | * 设置是否显示原始轨迹 271 | * 272 | * @param enable 273 | */ 274 | private void setOriginEnable(boolean enable) { 275 | mDisplaybtn.setClickable(true); 276 | if (mOriginPolyline == null || mOriginStartMarker == null 277 | || mOriginEndMarker == null || mOriginRoleMarker == null) { 278 | return; 279 | } 280 | if (enable) { 281 | mOriginPolyline.setVisible(true); 282 | mOriginStartMarker.setVisible(true); 283 | mOriginEndMarker.setVisible(true); 284 | mOriginRoleMarker.setVisible(true); 285 | } else { 286 | mOriginPolyline.setVisible(false); 287 | mOriginStartMarker.setVisible(false); 288 | mOriginEndMarker.setVisible(false); 289 | mOriginRoleMarker.setVisible(false); 290 | } 291 | } 292 | 293 | /** 294 | * 地图上添加纠偏后轨迹线路及起终点、轨迹动画小人 295 | * 296 | */ 297 | private void addGraspTrace(List graspList, boolean mGraspChecked) { 298 | if (graspList == null || graspList.size() < 2) { 299 | return; 300 | } 301 | LatLng startPoint = graspList.get(0); 302 | LatLng endPoint = graspList.get(graspList.size() - 1); 303 | mGraspPolyline = mAMap.addPolyline(new PolylineOptions() 304 | .setCustomTexture( 305 | BitmapDescriptorFactory 306 | .fromResource(R.drawable.grasp_trace_line)) 307 | .width(40).addAll(graspList)); 308 | mGraspStartMarker = mAMap.addMarker(new MarkerOptions().position( 309 | startPoint).icon( 310 | BitmapDescriptorFactory.fromResource(R.drawable.start))); 311 | mGraspEndMarker = mAMap.addMarker(new MarkerOptions() 312 | .position(endPoint).icon( 313 | BitmapDescriptorFactory.fromResource(R.drawable.end))); 314 | mGraspRoleMarker = mAMap.addMarker(new MarkerOptions().position( 315 | startPoint).icon( 316 | BitmapDescriptorFactory.fromBitmap(BitmapFactory 317 | .decodeResource(getResources(), R.drawable.walk)))); 318 | if (!mGraspChecked) { 319 | mGraspPolyline.setVisible(false); 320 | mGraspStartMarker.setVisible(false); 321 | mGraspEndMarker.setVisible(false); 322 | mGraspRoleMarker.setVisible(false); 323 | } 324 | } 325 | 326 | /** 327 | * 设置是否显示纠偏后轨迹 328 | * 329 | * @param enable 330 | */ 331 | private void setGraspEnable(boolean enable) { 332 | mDisplaybtn.setClickable(true); 333 | if (mGraspPolyline == null || mGraspStartMarker == null 334 | || mGraspEndMarker == null || mGraspRoleMarker == null) { 335 | return; 336 | } 337 | if (enable) { 338 | mGraspPolyline.setVisible(true); 339 | mGraspStartMarker.setVisible(true); 340 | mGraspEndMarker.setVisible(true); 341 | mGraspRoleMarker.setVisible(true); 342 | } else { 343 | mGraspPolyline.setVisible(false); 344 | mGraspStartMarker.setVisible(false); 345 | mGraspEndMarker.setVisible(false); 346 | mGraspRoleMarker.setVisible(false); 347 | } 348 | } 349 | 350 | @Override 351 | public void onMapLoaded() { 352 | Message msg = handler.obtainMessage(); 353 | msg.what = AMAP_LOADED; 354 | handler.sendMessage(msg); 355 | } 356 | 357 | /** 358 | * 轨迹纠偏完成数据回调 359 | */ 360 | @Override 361 | public void onFinished(int arg0, List list, int arg2, int arg3) { 362 | addGraspTrace(list, mGraspChecked); 363 | mGraspLatLngList = list; 364 | } 365 | 366 | @Override 367 | public void onRequestFailed(int arg0, String arg1) { 368 | Toast.makeText(this.getApplicationContext(), "轨迹纠偏失败:" + arg1, 369 | Toast.LENGTH_SHORT).show(); 370 | 371 | } 372 | 373 | @Override 374 | public void onTraceProcessing(int arg0, int arg1, List arg2) { 375 | 376 | } 377 | 378 | @Override 379 | public void onClick(View v) { 380 | int id = v.getId(); 381 | switch (id) { 382 | case R.id.displaybtn: 383 | if (mDisplaybtn.isChecked()) { 384 | startMove(); 385 | mDisplaybtn.setClickable(false); 386 | } 387 | break; 388 | case R.id.record_show_activity_grasp_radio_button: 389 | mGraspChecked = true; 390 | mOriginChecked = false; 391 | mGraspRadioButton.setChecked(true); 392 | mOriginRadioButton.setChecked(false); 393 | setGraspEnable(true); 394 | setOriginEnable(false); 395 | mDisplaybtn.setChecked(false); 396 | resetGraspRole(); 397 | break; 398 | case R.id.record_show_activity_origin_radio_button: 399 | mOriginChecked = true; 400 | mGraspChecked = false; 401 | mGraspRadioButton.setChecked(false); 402 | mOriginRadioButton.setChecked(true); 403 | setGraspEnable(false); 404 | setOriginEnable(true); 405 | mDisplaybtn.setChecked(false); 406 | resetOriginRole(); 407 | break; 408 | } 409 | } 410 | } 411 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/database/DbAdapter.java: -------------------------------------------------------------------------------- 1 | package amap.com.database; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | 9 | import android.content.ContentValues; 10 | import android.content.Context; 11 | import android.database.Cursor; 12 | import android.database.SQLException; 13 | import android.database.sqlite.SQLiteDatabase; 14 | import android.database.sqlite.SQLiteOpenHelper; 15 | 16 | import amap.com.record.PathRecord; 17 | import amap.com.recorduitl.Util; 18 | 19 | /** 20 | * 数据库相关操作,用于存取轨迹记录 21 | * 22 | */ 23 | public class DbAdapter { 24 | public static final String KEY_ROWID = "id"; 25 | public static final String KEY_DISTANCE = "distance"; 26 | public static final String KEY_DURATION = "duration"; 27 | public static final String KEY_SPEED = "averagespeed"; 28 | public static final String KEY_LINE = "pathline"; 29 | public static final String KEY_STRAT = "stratpoint"; 30 | public static final String KEY_END = "endpoint"; 31 | public static final String KEY_DATE = "date"; 32 | private final static String DATABASE_PATH = android.os.Environment 33 | .getExternalStorageDirectory().getAbsolutePath() + "/recordPath"; 34 | static final String DATABASE_NAME = DATABASE_PATH + "/" + "record.db"; 35 | private static final int DATABASE_VERSION = 1; 36 | private static final String RECORD_TABLE = "record"; 37 | private static final String RECORD_CREATE = "create table if not exists record(" 38 | + KEY_ROWID 39 | + " integer primary key autoincrement," 40 | + "stratpoint STRING," 41 | + "endpoint STRING," 42 | + "pathline STRING," 43 | + "distance STRING," 44 | + "duration STRING," 45 | + "averagespeed STRING," 46 | + "date STRING" + ");"; 47 | 48 | public static class DatabaseHelper extends SQLiteOpenHelper { 49 | public DatabaseHelper(Context context) { 50 | super(context, DATABASE_NAME, null, DATABASE_VERSION); 51 | } 52 | 53 | @Override 54 | public void onCreate(SQLiteDatabase db) { 55 | db.execSQL(RECORD_CREATE); 56 | } 57 | 58 | @Override 59 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 60 | } 61 | } 62 | 63 | private Context mCtx = null; 64 | private DatabaseHelper dbHelper; 65 | private SQLiteDatabase db; 66 | 67 | // constructor 68 | public DbAdapter(Context ctx) { 69 | this.mCtx = ctx; 70 | dbHelper = new DatabaseHelper(mCtx); 71 | } 72 | 73 | public DbAdapter open() throws SQLException { 74 | 75 | db = dbHelper.getWritableDatabase(); 76 | return this; 77 | } 78 | 79 | public void close() { 80 | dbHelper.close(); 81 | } 82 | 83 | public Cursor getall() { 84 | return db.rawQuery("SELECT * FROM record", null); 85 | } 86 | 87 | // remove an entry 88 | public boolean delete(long rowId) { 89 | 90 | return db.delete(RECORD_TABLE, "id=" + rowId, null) > 0; 91 | } 92 | 93 | /** 94 | * 数据库存入一条轨迹 95 | * 96 | * @param distance 97 | * @param duration 98 | * @param averagespeed 99 | * @param pathline 100 | * @param stratpoint 101 | * @param endpoint 102 | * @param date 103 | * @return 104 | */ 105 | public long createrecord(String distance, String duration, 106 | String averagespeed, String pathline, String stratpoint, 107 | String endpoint, String date) { 108 | ContentValues args = new ContentValues(); 109 | args.put("distance", distance); 110 | args.put("duration", duration); 111 | args.put("averagespeed", averagespeed); 112 | args.put("pathline", pathline); 113 | args.put("stratpoint", stratpoint); 114 | args.put("endpoint", endpoint); 115 | args.put("date", date); 116 | return db.insert(RECORD_TABLE, null, args); 117 | } 118 | 119 | /** 120 | * 查询所有轨迹记录 121 | * 122 | * @return 123 | */ 124 | public List queryRecordAll() { 125 | List allRecord = new ArrayList(); 126 | Cursor allRecordCursor = db.query(RECORD_TABLE, getColumns(), null, 127 | null, null, null, null); 128 | while (allRecordCursor.moveToNext()) { 129 | PathRecord record = new PathRecord(); 130 | record.setId(allRecordCursor.getInt(allRecordCursor 131 | .getColumnIndex(DbAdapter.KEY_ROWID))); 132 | record.setDistance(allRecordCursor.getString(allRecordCursor 133 | .getColumnIndex(DbAdapter.KEY_DISTANCE))); 134 | record.setDuration(allRecordCursor.getString(allRecordCursor 135 | .getColumnIndex(DbAdapter.KEY_DURATION))); 136 | record.setDate(allRecordCursor.getString(allRecordCursor 137 | .getColumnIndex(DbAdapter.KEY_DATE))); 138 | String lines = allRecordCursor.getString(allRecordCursor 139 | .getColumnIndex(DbAdapter.KEY_LINE)); 140 | record.setPathline(Util.parseLocations(lines)); 141 | record.setStartpoint(Util.parseLocation(allRecordCursor 142 | .getString(allRecordCursor 143 | .getColumnIndex(DbAdapter.KEY_STRAT)))); 144 | record.setEndpoint(Util.parseLocation(allRecordCursor 145 | .getString(allRecordCursor 146 | .getColumnIndex(DbAdapter.KEY_END)))); 147 | allRecord.add(record); 148 | } 149 | Collections.reverse(allRecord); 150 | return allRecord; 151 | } 152 | 153 | /** 154 | * 按照id查询 155 | * 156 | * @param mRecordItemId 157 | * @return 158 | */ 159 | public PathRecord queryRecordById(int mRecordItemId) { 160 | String where = KEY_ROWID + "=?"; 161 | String[] selectionArgs = new String[] { String.valueOf(mRecordItemId) }; 162 | Cursor cursor = db.query(RECORD_TABLE, getColumns(), where, 163 | selectionArgs, null, null, null); 164 | PathRecord record = new PathRecord(); 165 | if (cursor.moveToNext()) { 166 | record.setId(cursor.getInt(cursor 167 | .getColumnIndex(DbAdapter.KEY_ROWID))); 168 | record.setDistance(cursor.getString(cursor 169 | .getColumnIndex(DbAdapter.KEY_DISTANCE))); 170 | record.setDuration(cursor.getString(cursor 171 | .getColumnIndex(DbAdapter.KEY_DURATION))); 172 | record.setDate(cursor.getString(cursor 173 | .getColumnIndex(DbAdapter.KEY_DATE))); 174 | String lines = cursor.getString(cursor 175 | .getColumnIndex(DbAdapter.KEY_LINE)); 176 | record.setPathline(Util.parseLocations(lines)); 177 | record.setStartpoint(Util.parseLocation(cursor.getString(cursor 178 | .getColumnIndex(DbAdapter.KEY_STRAT)))); 179 | record.setEndpoint(Util.parseLocation(cursor.getString(cursor 180 | .getColumnIndex(DbAdapter.KEY_END)))); 181 | } 182 | return record; 183 | } 184 | 185 | private String[] getColumns() { 186 | return new String[] { KEY_ROWID, KEY_DISTANCE, KEY_DURATION, KEY_SPEED, 187 | KEY_LINE, KEY_STRAT, KEY_END, KEY_DATE }; 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/record/PathRecord.java: -------------------------------------------------------------------------------- 1 | package amap.com.record; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import com.amap.api.location.AMapLocation; 6 | 7 | /** 8 | * 用于记录一条轨迹,包括起点、终点、轨迹中间点、距离、耗时、平均速度、时间 9 | * 10 | * @author ligen 11 | * 12 | */ 13 | public class PathRecord { 14 | private AMapLocation mStartPoint; 15 | private AMapLocation mEndPoint; 16 | private List mPathLinePoints = new ArrayList(); 17 | private String mDistance; 18 | private String mDuration; 19 | private String mAveragespeed; 20 | private String mDate; 21 | private int mId = 0; 22 | 23 | public PathRecord() { 24 | 25 | } 26 | 27 | public int getId() { 28 | return mId; 29 | } 30 | 31 | public void setId(int id) { 32 | this.mId = id; 33 | } 34 | 35 | public AMapLocation getStartpoint() { 36 | return mStartPoint; 37 | } 38 | 39 | public void setStartpoint(AMapLocation startpoint) { 40 | this.mStartPoint = startpoint; 41 | } 42 | 43 | public AMapLocation getEndpoint() { 44 | return mEndPoint; 45 | } 46 | 47 | public void setEndpoint(AMapLocation endpoint) { 48 | this.mEndPoint = endpoint; 49 | } 50 | 51 | public List getPathline() { 52 | return mPathLinePoints; 53 | } 54 | 55 | public void setPathline(List pathline) { 56 | this.mPathLinePoints = pathline; 57 | } 58 | 59 | public String getDistance() { 60 | return mDistance; 61 | } 62 | 63 | public void setDistance(String distance) { 64 | this.mDistance = distance; 65 | } 66 | 67 | public String getDuration() { 68 | return mDuration; 69 | } 70 | 71 | public void setDuration(String duration) { 72 | this.mDuration = duration; 73 | } 74 | 75 | public String getAveragespeed() { 76 | return mAveragespeed; 77 | } 78 | 79 | public void setAveragespeed(String averagespeed) { 80 | this.mAveragespeed = averagespeed; 81 | } 82 | 83 | public String getDate() { 84 | return mDate; 85 | } 86 | 87 | public void setDate(String date) { 88 | this.mDate = date; 89 | } 90 | 91 | public void addpoint(AMapLocation point) { 92 | mPathLinePoints.add(point); 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | StringBuilder record = new StringBuilder(); 98 | record.append("recordSize:" + getPathline().size() + ", "); 99 | record.append("distance:" + getDistance() + "m, "); 100 | record.append("duration:" + getDuration() + "s"); 101 | return record.toString(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/recorduitl/Util.java: -------------------------------------------------------------------------------- 1 | package amap.com.recorduitl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.amap.api.location.AMapLocation; 7 | import com.amap.api.maps.model.LatLng; 8 | import com.amap.api.trace.TraceLocation; 9 | 10 | public class Util { 11 | /** 12 | * 将AMapLocation List 转为TraceLocation list 13 | * 14 | * @param list 15 | * @return 16 | */ 17 | public static List parseTraceLocationList( 18 | List list) { 19 | List traceList = new ArrayList(); 20 | if (list == null) { 21 | return traceList; 22 | } 23 | for (int i = 0; i < list.size(); i++) { 24 | TraceLocation location = new TraceLocation(); 25 | AMapLocation amapLocation = list.get(i); 26 | location.setBearing(amapLocation.getBearing()); 27 | location.setLatitude(amapLocation.getLatitude()); 28 | location.setLongitude(amapLocation.getLongitude()); 29 | location.setSpeed(amapLocation.getSpeed()); 30 | location.setTime(amapLocation.getTime()); 31 | traceList.add(location); 32 | } 33 | return traceList; 34 | } 35 | public static TraceLocation parseTraceLocation(AMapLocation amapLocation) { 36 | TraceLocation location = new TraceLocation(); 37 | location.setBearing(amapLocation.getBearing()); 38 | location.setLatitude(amapLocation.getLatitude()); 39 | location.setLongitude(amapLocation.getLongitude()); 40 | location.setSpeed(amapLocation.getSpeed()); 41 | location.setTime(amapLocation.getTime()); 42 | return location; 43 | } 44 | 45 | /** 46 | * 将AMapLocation List 转为LatLng list 47 | * @param list 48 | * @return 49 | */ 50 | public static List parseLatLngList(List list) { 51 | List traceList = new ArrayList(); 52 | if (list == null) { 53 | return traceList; 54 | } 55 | for (int i = 0; i < list.size(); i++) { 56 | AMapLocation loc = list.get(i); 57 | double lat = loc.getLatitude(); 58 | double lng = loc.getLongitude(); 59 | LatLng latlng = new LatLng(lat, lng); 60 | traceList.add(latlng); 61 | } 62 | return traceList; 63 | } 64 | 65 | public static AMapLocation parseLocation(String latLonStr) { 66 | if (latLonStr == null || latLonStr.equals("") || latLonStr.equals("[]")) { 67 | return null; 68 | } 69 | String[] loc = latLonStr.split(","); 70 | AMapLocation location = null; 71 | if (loc.length == 6) { 72 | location = new AMapLocation(loc[2]); 73 | location.setProvider(loc[2]); 74 | location.setLatitude(Double.parseDouble(loc[0])); 75 | location.setLongitude(Double.parseDouble(loc[1])); 76 | location.setTime(Long.parseLong(loc[3])); 77 | location.setSpeed(Float.parseFloat(loc[4])); 78 | location.setBearing(Float.parseFloat(loc[5])); 79 | }else if(loc.length == 2){ 80 | location = new AMapLocation("gps"); 81 | location.setLatitude(Double.parseDouble(loc[0])); 82 | location.setLongitude(Double.parseDouble(loc[1])); 83 | } 84 | 85 | return location; 86 | } 87 | 88 | public static ArrayList parseLocations(String latLonStr) { 89 | ArrayList locations = new ArrayList(); 90 | String[] latLonStrs = latLonStr.split(";"); 91 | for (int i = 0; i < latLonStrs.length; i++) { 92 | AMapLocation location = Util.parseLocation(latLonStrs[i]); 93 | if (location != null) { 94 | locations.add(location); 95 | } 96 | } 97 | return locations; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/test/EmulatorService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Name:LocationService 3 | * File Name:EmulatorService.java 4 | * Package Name:com.amap.apitest 5 | * Date:2015年11月27日下午1:39:49 6 | * 7 | */ 8 | /** 9 | */ 10 | 11 | package amap.com.test; 12 | 13 | import java.io.FileDescriptor; 14 | 15 | import android.app.Service; 16 | import android.content.Context; 17 | import android.content.Intent; 18 | import android.location.Criteria; 19 | import android.location.Location; 20 | import android.location.LocationManager; 21 | import android.location.LocationProvider; 22 | import android.os.Binder; 23 | import android.os.IBinder; 24 | import android.os.IInterface; 25 | import android.os.Parcel; 26 | import android.os.RemoteException; 27 | import android.os.SystemClock; 28 | import android.provider.Settings; 29 | import android.text.TextUtils; 30 | import android.util.Log; 31 | import android.widget.Toast; 32 | 33 | /** 34 | * ClassName:EmulatorService
35 | * Function: TODO ADD FUNCTION.
36 | * Reason: TODO ADD REASON.
37 | * Date: 2015年11月27日 下午1:39:49
38 | * @author yiyi.qi 39 | * @version 40 | * @since JDK 1.6 41 | * @see 42 | */ 43 | /** 44 | */ 45 | public class EmulatorService extends Service { 46 | public static double latitude; 47 | public static double longitude; 48 | 49 | public boolean isMockOpen() { 50 | 51 | String strMock = Settings.Secure.ALLOW_MOCK_LOCATION; 52 | strMock = Settings.Secure.getString(getApplicationContext() 53 | .getContentResolver(), strMock); 54 | if (!TextUtils.isEmpty(strMock) && !strMock.equals("0")) { 55 | /* 56 | * 系统设置中的允许MOCK选项已勾选 57 | */ 58 | return true; 59 | } 60 | return false; 61 | } 62 | private Thread thread = new Thread() { 63 | public void run() { 64 | while (true) { 65 | if (latitude == 0 || longitude == 0) { 66 | try { 67 | Thread.sleep(1000); 68 | } catch (InterruptedException e) { 69 | 70 | // TODO Auto-generated catch block 71 | e.printStackTrace(); 72 | 73 | } 74 | continue; 75 | } 76 | if(!isMockOpen()){ 77 | try { 78 | Thread.sleep(1000); 79 | } catch (InterruptedException e) { 80 | 81 | // TODO Auto-generated catch block 82 | e.printStackTrace(); 83 | 84 | } 85 | continue; 86 | } 87 | 88 | LocationManager locmanag = (LocationManager) EmulatorService.this 89 | .getSystemService(Context.LOCATION_SERVICE); 90 | String mock = LocationManager.GPS_PROVIDER; 91 | 92 | locmanag.addTestProvider(mock, false, true, false, false, 93 | false, false, false, 0, 5); 94 | locmanag.setTestProviderEnabled(mock, true); 95 | Location loc = new Location(mock); 96 | loc.setTime(System.currentTimeMillis()); 97 | 98 | // 下面这两句很关键 99 | loc.setLatitude(latitude); 100 | loc.setLongitude(longitude); 101 | 102 | loc.setAccuracy(Criteria.ACCURACY_FINE);// 精确�? 103 | loc.setSpeed(50); 104 | if (android.os.Build.VERSION.SDK_INT >= 17) { 105 | loc.setElapsedRealtimeNanos(SystemClock 106 | .elapsedRealtimeNanos());// 实时运行时间 107 | } 108 | locmanag.setTestProviderStatus(mock, 109 | LocationProvider.AVAILABLE, null, 110 | System.currentTimeMillis()); 111 | locmanag.setTestProviderLocation(mock, loc); 112 | try { 113 | Thread.sleep(1000); 114 | } catch (InterruptedException e) { 115 | 116 | e.printStackTrace(); 117 | 118 | } 119 | } 120 | 121 | } 122 | }; 123 | 124 | /** 125 | */ 126 | @Override 127 | public IBinder onBind(Intent intent) { 128 | 129 | thread.start(); 130 | // TODO Auto-generated method stub 131 | return new EmulatorBinder(); 132 | } 133 | 134 | public class EmulatorBinder extends Binder { 135 | 136 | public void setEmulatorLocation(double latitude, double longitude) { 137 | setLocation(latitude, longitude); 138 | } 139 | } 140 | 141 | private void setLocation(double latitude, double longitude) { 142 | this.latitude = latitude; 143 | this.longitude = longitude; 144 | 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /app/src/main/java/amap/com/tracereplay/TraceRePlay.java: -------------------------------------------------------------------------------- 1 | package amap.com.tracereplay; 2 | 3 | import java.lang.ref.WeakReference; 4 | import java.util.List; 5 | 6 | import android.os.Handler; 7 | import android.os.Looper; 8 | import android.os.Message; 9 | 10 | import com.amap.api.maps.model.LatLng; 11 | 12 | /** 13 | * 轨迹回放工具类 14 | * 15 | */ 16 | public class TraceRePlay implements Runnable { 17 | private TraceRePlayHandler mTraceHandler; 18 | private static final int TRACE_MOVE = 1; 19 | private static final int TRACE_FINISH = 2; 20 | private List mTraceList; 21 | private int mIntervalMillisecond; 22 | private TraceRePlayListener mTraceUpdateListener; 23 | private boolean mStop = false; 24 | 25 | /** 26 | * 构造轨迹回放需要,List、时间间隔、回调listenenr 27 | * 28 | * @param list 29 | * 轨迹list 30 | * @param intervalMillisecond 31 | * 回调时间间隔 32 | * @param listener 33 | * 回调listener 34 | */ 35 | public TraceRePlay(List list, int intervalMillisecond, 36 | TraceRePlayListener listener) { 37 | mTraceList = list; 38 | mIntervalMillisecond = intervalMillisecond; 39 | mTraceUpdateListener = listener; 40 | mTraceHandler = new TraceRePlayHandler(this); 41 | } 42 | 43 | public void stopTrace() { 44 | mStop = true; 45 | } 46 | 47 | /** 48 | * 接收run发送的消息,达到按照设定时间间隔轮巡轨迹list目的 49 | * 50 | */ 51 | static class TraceRePlayHandler extends Handler { 52 | WeakReference mTraceRePaly; 53 | 54 | public TraceRePlayHandler(TraceRePlay traceRePlay) { 55 | super(Looper.getMainLooper()); 56 | mTraceRePaly = new WeakReference(traceRePlay); 57 | } 58 | 59 | @Override 60 | public void handleMessage(Message message) { 61 | super.handleMessage(message); 62 | TraceRePlay trace = mTraceRePaly.get(); 63 | switch (message.what) { 64 | case TRACE_MOVE: 65 | LatLng latLng = (LatLng) message.obj; 66 | if (trace.mTraceUpdateListener != null) { 67 | trace.mTraceUpdateListener.onTraceUpdating(latLng); 68 | } 69 | break; 70 | case TRACE_FINISH: 71 | if (trace.mTraceUpdateListener != null) { 72 | trace.mTraceUpdateListener.onTraceUpdateFinish(); 73 | } 74 | break; 75 | default: 76 | break; 77 | } 78 | } 79 | } 80 | 81 | public interface TraceRePlayListener { 82 | /** 83 | * 轨迹回放过程回调 84 | * 85 | * @param latLng 86 | */ 87 | public void onTraceUpdating(LatLng latLng); 88 | 89 | /** 90 | * 轨迹回放结束回调 91 | */ 92 | public void onTraceUpdateFinish(); 93 | 94 | } 95 | 96 | /** 97 | * 将mTraceList 按照给定的时间间隔和次序发消息给TraceRePlayHandler以达到轨迹回放效果 98 | */ 99 | @Override 100 | public void run() { 101 | if (mTraceList != null) { 102 | for (int i = 0; i < mTraceList.size(); i++) { 103 | if (mStop) { 104 | break; 105 | } 106 | LatLng latLng = mTraceList.get(i); 107 | Message message = mTraceHandler.obtainMessage(); 108 | message.what = TRACE_MOVE; 109 | message.obj = latLng; 110 | mTraceHandler.sendMessage(message); 111 | try { 112 | Thread.sleep(mIntervalMillisecond); 113 | } catch (InterruptedException e) { 114 | e.printStackTrace(); 115 | } 116 | } 117 | if (!mStop) { 118 | Message finishMessage = mTraceHandler.obtainMessage(); 119 | finishMessage.what = TRACE_FINISH; 120 | mTraceHandler.sendMessage(finishMessage); 121 | } 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/back_btn_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/back_btn_image.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/end.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/grasp_flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/grasp_flag.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/grasp_trace_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/grasp_trace_line.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/point.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/point5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/point5.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/start.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/title_background.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/title_background.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/walk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/drawable/walk.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/basicmap_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 25 | 26 | 27 | 33 | 34 | 41 | 42 | 43 | 53 | 54 | 62 | 63 | 64 | 65 | 71 | 72 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recorddisplay_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 25 | 26 | 32 | 33 | 34 | 40 | 41 | 48 | 49 | 50 | 63 | 64 | 65 | 66 | 72 | 73 | 74 | 82 | 83 | 87 | 88 | 94 | 95 | 101 | 102 | 103 | 107 | 108 | 113 | 114 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recorditem.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recordlist.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | 12 | 24 | 25 | 31 | 32 | 33 | 39 | 40 | 47 | 48 | 49 | 58 | 59 | 66 | 67 | 68 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Android-path-record 3 | Hello world! 4 | Settings 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/amap/com/android_path_record/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package amap.com.android_path_record; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amap-demo/android-path-record/145cd018653f930632d6046c3e251650391dc7c7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------