【问题标题】:Android - How to add shadow in a custom MyLocationOverlayAndroid - 如何在自定义 MyLocationOverlay 中添加阴影
【发布时间】:2012-09-11 16:45:57
【问题描述】:

我想为 MyLocationOverlay 的自定义标记添加阴影。我已经尝试过使用this question:

  @Override
  protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
    mapView.getProjection().toPixels(myLocation, currentPoint);
    canvas.drawBitmap(markerBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null);
  }

  @Override
  public synchronized boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {

      if (getLastFix() == null) {
        return super.draw(canvas, mapView, shadow, when);
      }

      if (markerDrawable != null) {
          GeoPoint lastFixGeoPoint = new GeoPoint((int)(getLastFix().getLatitude() * 1E6), (int)(getLastFix().getLongitude() * 1E6));
          mapView.getProjection().toPixels(lastFixGeoPoint, currentPoint);

          drawAt(canvas, markerDrawable, currentPoint.x, currentPoint.y, shadow);
    } else if (getMyLocation() != null) {
        drawMyLocation(canvas, mapView, getLastFix(), getMyLocation(), when);
    }
      return super.draw(canvas, mapView, shadow, when);
}

我错过了什么? 提前致谢。

【问题讨论】:

    标签: android google-maps mylocationoverlay


    【解决方案1】:

    最后,我可以为 MyLocationOverlay 的自定义标记绘制阴影,如下所示:

    @Override
    protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
        mapView.getProjection().toPixels(myLocation, currentPoint);
    
        canvas.drawBitmap(shadowBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null);
        canvas.drawBitmap(markerBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null);
    }
    

    我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      相关资源
      最近更新 更多