gpt4 book ai didi

Android Mapview 平移和缩放太慢

转载 作者:搜寻专家 更新时间:2023-11-01 07:41:19 25 4
gpt4 key购买 nike

我开发了一个 GPS 应用程序,我在其中记录用户根并显示它在 map 上......但是查看我的路线时在 map 上平移非常慢, map 至少需要4或5秒才能响应手指轻扫……

我已经覆盖了 onDraw() 方法并绘制线条以显示路线......有没有更好的方法来做到这一点,以便平移成为比 "MyTracks" 更快......

谢谢大家......Pratap S.

最佳答案

我不得不做 something similar .我的尝试目前在 onDraw 中执行以下操作(为了可读性而简化 - 错误处理等被删除):

if ((bmap == null) || (lastZoom != mapv.getLatitudeSpan()))
{
// bitmap is null - so we haven't previously drawn the path, OR
// the map has been zoomed in/out, so we're gonna re-draw it anyway
// (alternatively, I could have tried scaling the bitmap... might
// be worth investigating if that is more efficient)

Projection proj = mapv.getProjection();

// store zoom level for comparing in the next onDraw
lastZoom = mapv.getLatitudeSpan();

// draw a path of all of the points in my route
GeoPoint start = routePoints.get(0);
Point startPt = new Point();
proj.toPixels(start, startPt);

Path path = new Path();
path.moveTo(startPt.x, startPt.y);

Point nxtPt;

for (GeoPoint nextPoint : routePoints)
{
nxtPt = new Point();
proj.toPixels(nextPoint, nxtPt);
path.lineTo(nxtPt.x, nxtPt.y);
}

// create a new bitmap, the size of the map view
bmap = Bitmap.createBitmap(mapv.getWidth(), mapv.getHeight(), Bitmap.Config.ARGB_8888);

// create an off-screen canvas to prepare new bitmap, and draw path on to it
Canvas offscreencanvas = new Canvas(bmap);
offscreencanvas.drawPath(path, mPaint);

// draw the bitmap of the path onto my map view's canvas
canvas.drawBitmap(bmap, 0, 0, null);

// make a note of where we put the bitmap, so we know how much we
// we need to move it by if the user pans the map
mapStartPosition = proj.fromPixels(0, 0);
}
else
{
// as we're in onDraw, we think the user has panned/moved the map
// if we're in here, the zoom level hasn't changed, and
// we've already got a bitmap with a drawing of the route path

Projection proj = mapv.getProjection();

// where has the mapview been panned to?
Point offsetPt = new Point();
proj.toPixels(mapStartPosition, offsetPt);

// draw the bitmap in the new correct location
canvas.drawBitmap(bmap, offsetPt.x, offsetPt.y, null);
}

它还不完美....例如,路径在缩放后立即结束在错误的位置 - 一旦用户开始平移就被移动到正确的位置。

但这是一个开始 - 并且比在每次 onDraw 调用时重新绘制路径更有效

希望这对您有所帮助!

关于Android Mapview 平移和缩放太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1998375/

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