2011-08-08 59 views
1

任何人都可以告訴我在Google地圖中座標之間畫線的簡單方法嗎?Google地圖中座標之間的繪製路線

我在Google上發現了一些結果,但我正在尋找一些簡單的東西。

+1

您的活動是一個MapActivity?或者您想啓動Google地圖? –

+0

相信我,您在Google上找到的內容儘可能簡單。 – Reno

+0

當你處理第三方API的時候,它不是關於我們想要怎麼做,而是關於它們是如何服務的:) – doNotCheckMyBlog

回答

4

使用這個簡單的代碼...可能是工作在你的應用程序

public class GPSLine extends MapActivity { 

    private List<Overlay> mapOverlays; 
    private Projection projection; 
    MapView mapView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mapView = (MapView) findViewById(R.id.mapview); 
     mapView.setBuiltInZoomControls(true); 
     mapView.setClickable(true); 

     mapOverlays = mapView.getOverlays(); 
     projection = mapView.getProjection(); 
     mapOverlays.add(new MyOverlay(null)); 

    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     return false; 
    } 


    class MyOverlay extends ItemizedOverlay { 

     private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); 
     public MyOverlay(Drawable defaultMarker) { 
      super(defaultMarker); 
      // TODO Auto-generated constructor stub 
     } 
     @Override 
     public void draw(Canvas canvas, MapView mapv, boolean shadow){ 
      super.draw(canvas, mapv, shadow); 

      Paint mPaint = new Paint(); 
      mPaint.setDither(true); 
      mPaint.setColor(Color.RED); 
      mPaint.setStyle(Paint.Style.FILL_AND_STROKE); 
      mPaint.setStrokeJoin(Paint.Join.ROUND); 
      mPaint.setStrokeCap(Paint.Cap.ROUND); 
      mPaint.setStrokeWidth(2); 

      GeoPoint gP1 = new GeoPoint(19240000,-99120000); 
      GeoPoint gP2 = new GeoPoint(37423157, -122085008); 

      Point p1 = new Point(); 
      Point p2 = new Point(); 

     Path path = new Path(); 

      projection.toPixels(gP1, p1); 
      projection.toPixels(gP2, p2); 

      path.moveTo(p2.x, p2.y); 
      path.lineTo(p1.x,p1.y); 

      canvas.drawPath(path, mPaint); 
     } 
     @Override 
     protected OverlayItem createItem(int i) { 
      // TODO Auto-generated method stub 
      return mOverlays.get(i); 
     } 
     @Override 
     public int size() { 
      // TODO Auto-generated method stub 
      return 0; 
     } 
    } 
} 
相關問題