可以“叠加"大小与android上的谷歌地图一起缩放?缩放、大小、地图、quot

2023-09-07 04:57:47 作者:忽有故人心上过,回首山河便是秋。两处相思同淋雪,此生也算共白

我已经能够使用MapActivity"和ItemizedOverlay"在带有 Eclipse 的 android 上的谷歌地图上绘制叠加层.但是当地图放大和缩小时,叠加层不会改变大小.

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.

在你的 Overlay 类中:

In your Overlay class:

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))));         
}
}

当您的叠加层从缩放中重新绘制时,标记将根据 MeterToRadius 比例调整其大小.希望对您有所帮助.

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