gpt4 book ai didi

android - 删除路径 ||行删除谷歌地图

转载 作者:行者123 更新时间:2023-11-29 22:26:02 25 4
gpt4 key购买 nike

使用 Android 谷歌地图 GPS ,并制定路径 在这里输入代码

public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);


GeoPoint p = new GeoPoint((int) (29.987574219703674 * 1E6),
(int) (31.44225418567575 * 1E6));
GeoPoint p2 = new GeoPoint((int) ( 29.98763859272003 * 1E6),
(int) (31.44235074520111 * 1E6));
GeoPoint p3 = new GeoPoint((int) (29.98718498160553* 1E6),
(int) (31.442527770996094 * 1E6));
GeoPoint p4= new GeoPoint((int) (29.98739718380868 * 1E6),
(int) (31.442527770886084 * 1E6));

// Let's assume you've assigned values to these two GeoPoints now.

Projection projection = mapView.getProjection();
Point startingPoint = projection.toPixels(p, null);

Point endingPoint = projection.toPixels(p2, null);

// Create the path containing the line between the two points.
Path path = new Path();
path.moveTo(startingPoint.x, startingPoint.y);
path.lineTo(endingPoint.x, endingPoint.y);

// Setup the paint. You'd probably do this outside of the draw() method
// to be more efficient.
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.RED);


super.draw(canvas, mapView, shadow);
// el super de 3shnnn to addd koloooo overlay w path
canvas.drawPath(path, paint);

}

如果我想删除 Path1 怎么办呢?请帮忙

最佳答案

一个选项是创建一个名为“drawPath”的 bool 值。将绘制路径的所有逻辑放在 if 语句中:

public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
if(drawPath){
// path drawing logic goes here
}
}

然后当你想绘制路径时,将“drawPath”设置为true并调用View.Invalidate强制重绘 View 。当你想删除路径时,将“drawPath”设置为false并调用View.Invalidate。

关于android - 删除路径 ||行删除谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5943342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com