CAN"覆盖"尺寸与Android上的谷歌地图一起缩放?缩放、尺寸、地图、CAN

2023-09-05 07:24:32 作者:苍白无力旳爱

我已经能够使用MapActivity和ItemizedOverlay绘制覆盖在谷歌地图Android上使用Eclipse。但是,当图被放大和缩小,覆盖层不改变大小。

I have been able to use "MapActivity" and "ItemizedOverlay" to draw overlays on google maps on android with Eclipse. But when the map is zooming in and out, the overlay does not change size.

我想覆盖要在地图上的固定的,并放大和缩小以及与地图。如何才能做到这一点?

I want the overlay to be "fixed" on the map, and zoom in and out along with the map. How can this be done?

我找不到教程来定义的边界(例如使用GPS坐标的角落的叠加图像)。请提供链接,如果你知道一些。

I can't find the tutorial to define a boundary (e.g. with GPS coordinates as corners for the overlay image). Please provide links if you know some.

和做任何其他方式?

非常感谢。

推荐答案

是的,有。我和我的应用程序有同样的问题。下面是一个例子,它完美的作品。这里所画的圆鳞,你在地图的放大和缩小。

Yes, there is. I had the same issue with my application. Here's an example and it works perfectly. The circle drawn here scales as you zoom in and out of the map.

在您的覆盖类:

public class ImpactOverlay extends Overlay {

private static int CIRCLERADIUS = 0;
private GeoPoint geopoint;

public ImpactOverlay(GeoPoint point, int myRadius) {
    geopoint = point;
    CIRCLERADIUS = myRadius;
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    // Transfrom geoposition to Point on canvas
    Projection projection = mapView.getProjection();
    Point point = new Point();
    projection.toPixels(geopoint, point);

    // the circle to mark the spot
    Paint circle = new Paint();
    circle.setColor(Color.BLACK);
    int myCircleRadius = metersToRadius(CIRCLERADIUS, mapView, (double)geopoint.getLatitudeE6()/1000000);
    canvas.drawCircle(point.x, point.y, myCircleRadius, circle);
}

public static int metersToRadius(float meters, MapView map, double latitude) {
    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
}
}

随着覆盖从变焦重新绘制,标记将与它的基础上metersToRadius规模的调整。希望它能帮助。

As your overlay re-draws from zoom, the marker will resize with it based on the metersToRadius scale. Hope it helps.