高德地图-绘制个人历史位置路线
思路:将当前个人位置(经纬度信息)存储到手机数据库(SQLITE)中,然后遍历数据库中的所有位置信息,并绘制到MAP图层上。
1.数据库帮助类:
[java]
package com.example.touchpoint;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class MysqliteHelper extends SQLiteOpenHelper{
private static final String DATABASE_NAME = "my.db";
private static final int DATABASE_VERSION = 1;
public static final String COLUMN_ID = "_id"; //必须的
public static final String COLUMN_LATITUDE = "latitude";
public static final String COLUMN_LONGITUDE = "longitude";
public static final String COLUMN_UPLOAD_TIME = "upload_time"; //暂时没用
public static final String[] allColumns = {COLUMN_ID,COLUMN_LATITUDE,COLUMN_LONGITUDE};
private static final String CREATE_TABLE = "create table if not exists routlist"
+ "("
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_LATITUDE + " REAL not null, "
+ COLUMN_LONGITUDE + " REAL not null "
+ ");";
public MysqliteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d("CREATE_TABLE",CREATE_TABLE);
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table " + CREATE_TABLE);
onCreate(db);
}
}
2.数据库DAO
[java]
package com.example.touchpoint;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
public class SqliteDAO {
private SQLiteDatabase db;
private MysqliteHelper helper;
public SqliteDAO(Context context) {
helper = new MysqliteHelper(context);
}
public void open() {
db = helper.getWritableDatabase();
}
public void close() {
helper.close();
}
public void writePositionToDB(double latitude,double longitude) {
ContentValues values = new ContentValues();
values.put(MysqliteHelper.COLUMN_LATITUDE, latitude);
values.put(MysqliteHelper.COLUMN_LONGITUDE, longitude);
db.insert("routlist", null, values);
}
public List<LocationPoint> getAllPoints() {
List<LocationPoint> points = new ArrayList<LocationPoint>();
Cursor cursor = db.query("routlist", MysqliteHelper.allColumns, null, null,
null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
LocationPoint point = cursorToPoint(cursor);
points.add(point);
cursor.moveToNext();
}
// 记得关闭cursor对象
cursor.close();
return points;
}
private LocationPoint cursorToPoint(Cursor cursor) {
LocationPoint point = new LocationPoint();
point.set_id(cursor.getLong(0));
point.setLatitude(cursor.getDouble(1));
point.setLongitutde(cursor.getDouble(2));
Log.d("route",point.toString());
return point;
}
}
3.POJO类:
[java]
package com.example.touchpoint;
public class LocationPoint {&n
补充:软件开发 , Java ,