连接上线图点 [英] Connect points on map with lines

查看:123
本文介绍了连接上线图点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用程序三个GPS点。如何在地图上设置连接的第一和第二的红色和第二和第三,蓝线?如何连接在地图上的任何两个点,画出它们之间的线?

I have three gps points in android app. How to set on map connect first and second with red and second and third with blue line ? How to connect any two points on map, draw line between them?

推荐答案

下面是一个最小的实施(仅得2分,无标记)使用地图覆盖和MapView.getProjection()在你来回要在扩大:

Here's a minimal implementation (2 points only, no markers) using a map overlay and mapView.getProjection() fro you to expand upon:

    public class HelloGoogleMaps extends  MapActivity  {
    /** Called when the activity is first created. */

   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MapController mMapController;
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mMapController = mapView.getController();
        mMapController.setZoom(18);
      // Two points in Mexico about 1km apart
        GeoPoint point1 = new GeoPoint(19240000,-99120000);
        GeoPoint point2 = new GeoPoint(19241000,-99121000);
        mMapController.setCenter(point2);
        // Pass the geopoints to the overlay class
        MapOverlay mapOvlay = new MapOverlay(point1, point2);
        mapView.getOverlays().add(mapOvlay);
    }

    public class MapOverlay extends com.google.android.maps.Overlay {

      private GeoPoint mGpt1;
      private GeoPoint mGpt2;

      protected MapOverlay(GeoPoint gp1, GeoPoint gp2 ) {
         mGpt1 = gp1;
         mGpt2 = gp2;
      }
      @Override
      public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {
         super.draw(canvas, mapView, shadow);
         Paint paint;
         paint = new Paint();
         paint.setColor(Color.RED);
         paint.setAntiAlias(true);
         paint.setStyle(Style.STROKE);
         paint.setStrokeWidth(2);
         Point pt1 = new Point();
         Point pt2 = new Point();
         Projection projection = mapView.getProjection();
         projection.toPixels(mGpt1, pt1);
         projection.toPixels(mGpt2, pt2);
         canvas.drawLine(pt1.x, pt1.y, pt2.x, pt2.y, paint);
         return true;
      }
   }
   @Override
   protected boolean isRouteDisplayed() {
      // TODO Auto-generated method stub
      return false;
   }
}

这篇关于连接上线图点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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