How to draw a line on a map View given coordinates?

How to draw a line at MapViewgiven coordinates?

AFAIK, on ​​the iPhone you can.

Please inform.

Thanks in advance.

+5
source share
2 answers

To use MapView, your Activity must extend MapActivity .

For each line you want to draw (or really something else), you need to subclass Overlay and draw the drawing in Overlay onDraw(). After creating your own Overlay, add it in MapViewwith something like mMapView.getOverlays().add(new MyOverlay());.

Overlay Projection - Projection p = mapView.getProjection();. Projection GPS Projection toPixels (GeoPoint, Point), Canvas, 2D 2D.

... - , .

+21

, .

    //...setting map and starting 

    ArrayList<LatLng> list = new ArrayList<>();
    list.add(new LatLng(41.020244, 29.045663));
    list.add(new LatLng(41.019904, 29.045448));
    list.add(new LatLng(41.019451, 29.044397));
    list.add(new LatLng(41.019710, 29.043474));


    PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
    for (int z = 0; z < list.size(); z++) {
        LatLng point = list.get(z);
        options.add(point);
    }
    mGoogleMap.addPolyline(options);

    CameraPosition cameraPosition;
    cameraPosition = new CameraPosition.Builder().target(new LatLng(41.020811, 29.046113)).zoom(15).build();

    mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
0

All Articles