我在一个简单的任务上遇到了麻烦。
我正在尝试在如下所示的地图左上角绘制一个正方形。(地图投影左上角)
但是,当我使用 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。而且这条路径是在屏幕上而不是在地图上绘制的。所以当我滚动离开时,这条路径会随着地图移动......我不想要那样。