android - 如何在设备在 android 中移动时在谷歌地图上移动标记(当前标记)

标签 android android-maps

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

import android.content.Context;
import android.widget.Toast;

import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

// This class subclasses (extends) MyLocationOverlay so that we can override its dispatchTap method
// to handle tap events on the present location dot.

public class MyMyLocationOverlay extends MyLocationOverlay {

private Context context;

public MyMyLocationOverlay(Context context, MapView mapView) {
    super(context, mapView);
    this.context = context;   // Will need this for Toast argument below
}

// Override the dispatchTap() method to toggle the data display on and off when
// the present location dot is tapped. Also display a short Toast (transient message) to the
// user indicating the display status change.

@Override
protected boolean dispatchTap(){
    if(DisplayOverlay.showData){ 
        Toast.makeText(context, "Suppressing data readout", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(context,"Display data readout", Toast.LENGTH_SHORT).show();
    }
    // Toggle the GPS data display
    DisplayOverlay.showData = ! DisplayOverlay.showData;
    return true;
}

最佳答案

检查我的帖子答案有链接。

how to display map in android with marker

要在 map 上移动标记,您需要在类中创建静态方法来扩展 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);
}

此处使用 Bitmap 类在 map 上绘制图像来显示可绘制图像显示。

关于android - 如何在设备在 android 中移动时在谷歌地图上移动标记(当前标记),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7428865/

相关文章:

java - 使用像 android.R 这样的自定义命名空间创建 android 资源库?

android - 在 Android 上使用 OpenSL ES 通过套接字通信流式传输 MP3 音频

android - 每分钟运行的服务

android - 使用 Android map 进行车辆跟踪

android - 删除 Google 地点图标

android - V2 map 库是否需要 ACCESS_NETWORK_STATE 权限?

android - cordova 联系人插件联系人数据正在复制而不是覆盖联系人数据

java - 我该如何解决 "cd: can' t cd to/data/data/package_name/databases 的错误?

android - 当用户拒绝应用程序中的权限时怎么办?

android - 从另一个、距离和极角确定一个地理点