Android 当设备在安卓系统中移动时,如何在谷歌地图上移动标记(当前标记)

Android 当设备在安卓系统中移动时,如何在谷歌地图上移动标记(当前标记),android,android-maps,Android,Android Maps,如何在设备移动(用户移动)时移动谷歌地图上的标记(如点) 检查我的帖子答案有链接 要在地图上移动标记,您需要在your类中创建静态方法,该方法扩展了MapActivity,如 private static GeoPoint markerPoint; public static void updateLocation(Location location){ lat = location.getLatitude(); lng = location.getLongitude();

如何在设备移动(用户移动)时移动谷歌地图上的标记(如点)


检查我的帖子答案有链接

要在地图上移动标记,您需要在your类中创建静态方法,该方法扩展了MapActivity,如

private static GeoPoint markerPoint;

public static void updateLocation(Location location){
   lat = location.getLatitude();
   lng = location.getLongitude();

   // now use this lat/lng value to convert into the GeoPoint object

   markerPoint = new GeoPoint(lat * 1e6, lng * 1e6);
   mapview.invalidate();
}
扩展覆盖类的自定义覆盖类

public void draw(Canvas canvas, MapView mapView, boolean Shadow){
    Point screenPts = new Point();
    mapView.getProjection().toPixels(markerPoint, screenPts);
    //---add the marker---
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.cur_loc_1);
    canvas.drawBitmap(bmp, screenPts.x-(xCurLocOffset), screenPts.y-yCurLocOffset, null);
}

使用位图类在地图上绘制图像来显示可绘制图像显示。

Hi,为什么要从screenPts x&y坐标中减去xCurLocaOffset和yCurLocaOffset?我在代码中使用了相同的东西,但没有减去xCurLocaOffset&yCurLocaOffset,并且绘制了位图,但没有在确切的位置,但它稍微正确。为什么会这样?你能帮忙吗?我已经减去了位图的x和y偏移量,以便将标记放置在完美的位置上。这取决于您作为标记显示的图像/绘图
public void draw(Canvas canvas, MapView mapView, boolean Shadow){
    Point screenPts = new Point();
    mapView.getProjection().toPixels(markerPoint, screenPts);
    //---add the marker---
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.cur_loc_1);
    canvas.drawBitmap(bmp, screenPts.x-(xCurLocOffset), screenPts.y-yCurLocOffset, null);
}