简体   繁体   English

许多GeoPoints之间的MapView显示路线

[英]MapView display route between a lot of GeoPoints

I have an app where an user is given a lot of points (100 or even more) and he has to physically go to those points and "check in". 我有一个应用程序,其中向用户分配了很多积分(100个甚至更多),他必须亲自去这些积分并“签到”。 They have to go to those points in a certain order, so I need to display a route in the MapView which passes through all those points. 它们必须按一定顺序到达这些点,因此我需要在MapView中显示一条路线,该路线会穿过所有这些点。

I've read a lot about getting the route between two points, but I can't find anything about drawing a complex route with a lot of points. 我已经读了很多关于获取两点之间路线的信息,但是我找不到关于绘制具有很多点的复杂路线的信息。 Is this behavior possible? 这可能吗?

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));
   }
}

Try something like this 试试这个

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;      
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM