Drawing a line/path on Google Maps

后端 未结 13 842
执笔经年
执笔经年 2020-11-22 05:23

I\'ve been busy for a long time finding out how to draw a line between two (GPS) points on the map in HelloMapView but with no luck.

Could anyone please tell me how

13条回答
  •  鱼传尺愫
    2020-11-22 05:35

    Try this one:
    Add itemizedOverlay class:
    
    public class AndroidGoogleMapsActivity extends MapActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            // Displaying Zooming controls
            MapView mapView = (MapView) findViewById(R.id.mapview);
            mapView.setBuiltInZoomControls(true);
    
    
            MapController mc = mapView.getController();
            double lat = Double.parseDouble("48.85827758964043");
            double lon = Double.parseDouble("2.294543981552124");
            GeoPoint geoPoint = new GeoPoint((int)(lat * 1E6), (int)(lon * 1E6));
            mc.animateTo(geoPoint);
            mc.setZoom(15);
            mapView.invalidate(); 
    
    
            /**
             * Placing Marker
             * */
            List mapOverlays = mapView.getOverlays();
            Drawable drawable = this.getResources().getDrawable(R.drawable.mark_red);
            AddItemizedOverlay itemizedOverlay = 
                 new AddItemizedOverlay(drawable, this);
    
    
            OverlayItem overlayitem = new OverlayItem(geoPoint, "Hello", "Sample Overlay item");
    
            itemizedOverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedOverlay);
    
        }
    
        @Override
        protected boolean isRouteDisplayed() {
            return false;
        }
    }
    

提交回复
热议问题