0

我有一个应用程序,用户获得了很多积分(100 甚至更多),他必须亲自去这些积分并“签到”。他们必须按特定顺序前往这些点,所以我需要在 MapView 中显示一条通过所有这些点的路线。

我已经阅读了很多关于获取两点之间的路线的内容,但是我找不到任何关于绘制具有很多点的复杂路线的信息。这种行为可能吗?

4

2 回答 2

1
public class RouteOverlay extends Overlay {
    private GeoPoint gp1;
    private GeoPoint gp2;
    private int color;

public RouteOverlay(GeoPoint gp1, GeoPoint gp2, int color) {
        this.gp1 = gp1;
        this.gp2 = gp2;
        this.color = color;
    }
Now all that's left now for our Overlay is to override the draw() method and draw the line as we need it:

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    Projection projection = mapView.getProjection();
    Paint paint = new Paint();
    Point point = new Point();
    projection.toPixels(gp1, point);
    paint.setColor(color);
    Point point2 = new Point();
    projection.toPixels(gp2, point2);
    paint.setStrokeWidth(5);
    paint.setAlpha(120);
    canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
    super.draw(canvas, mapView, shadow);
}
Back in the Activity, just iterate over the GeoPoints that you got from google maps and add each of them to the MapView:

private void drawPath(List geoPoints, int color) {
   List overlays = mapView.getOverlays();

   for (int i = 1; i < geoPoints.size(); i++) {
    overlays.add(new RouteOverlay(geoPoints.get(i - 1), geoPoints.get(i), color));
   }
}
于 2012-12-10T12:32:06.963 回答
0

尝试这样的事情

if(DataSources.ActivitiesList.length >0)
{
  String address = "http://maps.google.com/maps?daddr=" +    DataSources.ActivitiesList[0].SiteLatitude.toString() + "," + DataSources.ActivitiesList[0].SiteLongitude.toString();
for (int i= 1 ;i <  DataSources.ActivitiesList.length ; i++) 
{
    if(DataSources.ActivitiesList[i].SiteLatitude != null)
        address += "+to:" + DataSources.ActivitiesList[i].SiteLatitude + "," + DataSources.ActivitiesList[i].SiteLongitude;
}
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(address));
    startActivity(intent);
    break;      
}
于 2012-12-10T12:19:23.137 回答