绘制路径跟踪您的位置在谷歌地图Android版 [英] Draw a path following your location on Google Maps for Android

查看:102
本文介绍了绘制路径跟踪您的位置在谷歌地图Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序的,我需要在谷歌地图的显示,用户已经改变位置要绘制的路径。我已经使用MyLocationOverlay类想我可以只覆盖,吸引了位置的方法试过,但我已经决定用什么方法重写是不成功的。此外,它似乎MyLocationOverlay每个位置绘制时间绘制一个新的地图。我目前使用的是ItemizedOverlay,只是有一个点添加到列表中,每次的位置变化。这工作,我也得到一个虚线路径,我走,但我真的想了坚实的路径。有没有什么建议?

I am working on an app for which I need a path to be drawn on a Google map as the location changes showing where the user has been. I have tried using the MyLocationOverlay class thinking I could just override the method that draws the location but I have been unsuccessful in determining what method to override. Also, it appears that MyLocationOverlay draws a new map every time the location is drawn. I am currently using an ItemizedOverlay and just having a dot added to the list every time the location changes. This works, and I get a dotted path as I walk but I would really like a solid path. Are there any suggestions?

我也看到了这<一href="http://stackoverflow.com/questions/5578934/how-to-draw-path-on-google-map-as-i-am-moving">post但我不能得到它的工作。不要你需要一个覆盖序得到它在地图上?

I have also seen this post but I can't get it to work. Dont you need an overlay inorder to get it on the map?

推荐答案

我觉得这样做将是子类覆盖类,然后重写draw方法最简单的方法。抽签的方法是pretty的开结束,应该不会太难绘制路径。一个例子是这个样子:

I think the easiest way to do this would be to subclass the Overlay class, and then override the draw method. The draw method is pretty open ended and it shouldn't be too hard to draw a path. An example would look something like this:

public class PathOverlay extends Overlay{

    private List<GeoPoint> gpoints;

    public PathOverlay(List<GeoPoint> gpoints){
        this.gpoints = gpoints;
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
    {
        List<Point> mpoints = new ArrayList<Point>();

        // Convert to a point that can be drawn on the map.
        for(GeoPoint g : gpoints){
            Point tpoint = new Point();
            mapView.getProjection().toPixels(g, tpoint);
            mpoints.add(tpoint);
        }

        Path path = new Path();

        // Create a path from the points
        path.moveTo(mpoints.get(0).x, mpoints.get(0).y);
        for(Point p : mpoints){
            path.lineTo(p.x, p.y);
        }

        Paint paint = new Paint();
        paint.setARGB(255, 255, 0, 0);
        paint.setStyle(Style.STROKE);
        // Draw to the map
        canvas.drawPath(path,paint);

        return true;

    }
}

这个类的对象可以被添加到由调用MapView.getOverlays返回的列表()被添加到地图

Objects of this class can then be added to the list returned by MapView.getOverlays() to be added to the map.

这篇关于绘制路径跟踪您的位置在谷歌地图Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆