Mapview geopoint正在举行屏幕

时间:2012-05-03 14:27:40

标签: android android-mapview projection

我在一项简单的任务上遇到了麻烦。

我正在尝试在下面显示的地图的左上角画一个正方形。 (地图投影的左上角)

enter image description here

但是当我使用TileSystem(TileSystem.PixelXYToLatLong)将像素0,0转换为纬度和经度时,该点看起来像是在屏幕上绘制而不是在地图上绘制...为什么?

代码:

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    // Translate point to x y coordinates on the screen

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);

    Point point1_draw = new Point();
    Point point2_draw = new Point();
    Point point3_draw = new Point();
    Point point4_draw = new Point();

    mapView.getProjection().toPixels(geoPointFromScreenCoords(0,0,mapView),
            point1_draw);
    mapView.getProjection().toPixels(geoPointFromScreenCoords(0,100,mapView),
            point2_draw);
    mapView.getProjection().toPixels(geoPointFromScreenCoords(100,0,mapView),
            point3_draw);
    mapView.getProjection().toPixels(geoPointFromScreenCoords(100,100,mapView),
            point4_draw);

    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(point1_draw.x, point1_draw.y);
    path.lineTo(point2_draw.x, point2_draw.y);
    path.lineTo(point3_draw.x, point3_draw.y);
    path.lineTo(point4_draw.x, point4_draw.y);
    path.lineTo(point1_draw.x, point1_draw.y);
    path.close();

     //canvas.drawCircle(120, 20, 15, paint);
    canvas.drawPath(path, paint);

    super.draw(canvas, mapView, false);


}`

我正在扩展ItemizedOverlay。此路径在屏幕上绘制,而不是在地图上绘制。因此,当我向外滚动时,这条路径随地图一起移动......我不想要那个。

1 个答案:

答案 0 :(得分:0)

为什么要覆盖draw而不是addItem

以下是关于如何在地图上绘图的video