.getLastKnownLocation(LocationProviderProxy.MapABCNetwork);
mapOverlayList.add(new MyOverlay(this, new GeoPoint((int) (last
.getLatitude() * 1E6), (int) (last.getLongitude() * 1E6))));
locationProxy.requestLocationUpdates(LocationManagerProxy.GPS_PROVIDER,
0, 0, this); // 开始监听位置变化
}
public void onLocationChanged(Location location) {
mapOverlayList.clear();
if (location != null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
dao.writePositionToDB(latitude, longitude); // 写进数据库
GeoPoint gp = new GeoPoint((int) (latitude * 1E6),
(int) (longitude * 1E6));
overlay = new MyOverlay(this, gp);
mapOverlayList.add(overlay);
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
public void onProviderDisabled(String provider) {
}
}
class MyOverlay extends Overlay {
private Context mContext;
private GeoPoint gp;
private Bitmap bitmap;
public MyOverlay(Context mContext, GeoPoint gp) {
this.mContext = mContext;
this.gp = gp;
bitmap = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.new_func_dot);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection proj = mapView.getProjection();
Point mPoint = proj.toPixels(gp, null);
canvas.drawBitmap(bitmap, mPoint.x, mPoint.y, null);
super.draw(canvas, mapView, shadow);
}
}