android - 动画可绘制 MyLocationOverlay()

标签 android google-maps mylocationoverlay

是否可以覆盖 MyLocationOverlay() 的 onDraw 方法并用其他内容替换标准的闪烁蓝色图标。我可以通过哪些方法来实现这一点?

最佳答案

这里很好地回答了你的问题: myLocationOverlay change the marker

drawMyLocation(..)函数中绘制动画GIF图像。 Display Animated GIF

public class CurrentLocationOverlay extends MyLocationOverlay {

  // TODO: use dynamic calculation?
  private final static int PADDING_ACTIVE_ZOOM     = 50;

  private MapController    mc;
  private Bitmap           marker;
  private Point            currentPoint            = new Point();

  private boolean          centerOnCurrentLocation = true;

  private int              height;
  private int              width;

  /**
   * By default this CurrentLocationOverlay will center on the current location, if the currentLocation is near the
   * edge, or off the screen. To dynamically enable/disable this, use {@link #setCenterOnCurrentLocation(boolean)}.
   *
   * @param context
   * @param mapView
   */
  public CurrentLocationOverlay(Context context, MapView mapView) {
    super(context, mapView);
    this.mc = mapView.getController();
    this.marker = BitmapFactory.decodeResource(context.getResources(), R.drawable.position);
  }

  @Override
  protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
    // TODO: find a better way to get height/width once the mapView is layed out correctly
    if (this.height == 0) {
      this.height = mapView.getHeight();
      this.width = mapView.getWidth();
    }
    mapView.getProjection().toPixels(myLocation, currentPoint);
    canvas.drawBitmap(marker, currentPoint.x, currentPoint.y - 40, null);
  }

  @Override
  public synchronized void onLocationChanged(Location location) {
    super.onLocationChanged(location);
    // only move to new position if enabled and we are in an border-area
    if (mc != null && centerOnCurrentLocation && inZoomActiveArea(currentPoint)) {
      mc.animateTo(getMyLocation());
    }
  }

  private boolean inZoomActiveArea(Point currentPoint) {
    if ((currentPoint.x > PADDING_ACTIVE_ZOOM && currentPoint.x < width - PADDING_ACTIVE_ZOOM)
        && (currentPoint.y > PADDING_ACTIVE_ZOOM && currentPoint.y < height - PADDING_ACTIVE_ZOOM)) {
      return false;
    }
    return true;
  }

  public void setCenterOnCurrentLocation(boolean centerOnCurrentLocation) {
    this.centerOnCurrentLocation = centerOnCurrentLocation;
  }
}

关于android - 动画可绘制 MyLocationOverlay(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5929742/

相关文章:

android - Html 文本与 Android 中 Textview 中的图像重叠

javascript - 为什么我的自定义标记没有显示在 Google map 中?

google-maps - 如何使用 kotlin 设置 onmylocationbuttonclicklistener?

android - osmdroid 中的 MyLocationOverlay

Android 谷歌地图 API V2 : How to change my location icon?

java - 在 Android ContentProvider 中从网络同步时防止网络同步循环

android - 一个 .txt 到可修改的 android 数据库

android - Nexus 4.4.2 和 Samsung 4.1.2 在阅读屏幕内容时的 TalkBack 差异

google-maps - 在Google Maps API中删除或涂上赤道和国际日期线

javascript - Google map 折线 - 如何删除它?