0

我是 Android 的新开发者。我想开发地图应用程序。我想在地图上绘制折线,类似于在 Google Ma 上获取方向。绘制折线后,我可以沿折线绘制多边形吗?我不知道怎么做。请给我一个例子或一些解决方案。非常感谢,对不起我的英语。有可能吗?

这是图片 [https://www.dropbox.com/s/nmusjt6fp880akf/20-Jun-13%204-05-25%20PM.png][1]

4

1 回答 1

0

您可以使用Canvas Path PointClass 在 Google Map 上绘制折线。您还需要查看 此链接以供参考。

List<Overlay> mapOverlay;

  protected onCreate(Bundle savedInstanceStae){

     //Do the rest stuffs

      mapOverlay = mapView.getOverLays();

      mapOverlay.add(new MyOverlay());


     }


class MyOverLay extends Overlay{

       public MyOverlay(){}

       ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();

       public void draw(Canvas canvas,MapView mv, boolean shadow){
            super.draw(canvas,mv,shadow);

         Paint mPaint = new Paint();
         mPiant.setColor(Color.RED);
          //set strokewidth and all function depending upon you how you want to give a look                 

          //on Polyline.

        GeoPOint gp1 = new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0));
        GeoPOint gp2 = new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0));
        GeoPOint gp3 = new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0));
       GeoPOint gp4 = new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0));



     points.add(gp1);
     points.add(gp2);
     points.add(gp3);
     points.add(gp4);

     //Then take two points class object:

    Point point1 = new Point();

    Point point2 = new Point();

    Path path = new Path();

    for(int i = 0; i<points.size(); i++){

      projection.toPixel(points.get(i),point1);
      projection.toPixel(points.get(i+1),point2);

      path.moveTo(point2.x,point2.y);
       path.lineTo(point1.x,point1.y);

     }

   canvas.drawPath(path, mPoint);


}
于 2013-06-20T05:46:52.023 回答