Multi color Polyline in google map v2 in android

前端 未结 3 1718
长发绾君心
长发绾君心 2021-01-21 03:35

I searched a lot i didn\'t find any proper solution for it.Help and link could be appreciated :-)

3条回答
  •  隐瞒了意图╮
    2021-01-21 04:02

    Try this -

    @Override
    public void onMapReady(GoogleMap map) {
        // Add a thin red line from A to B.
        Polyline line1 = map.addPolyline(new PolylineOptions()
            .add(new LatLng(40.1, -74.2), new LatLng(40.7, -74.0))
            .width(5)
            .color(Color.RED)); 
    

    and then another line from B to C with a different color and so on

    Polyline line2 = map.addPolyline(new PolylineOptions()
         .add(new LatLng(40.7, -74.0), new LatLng(41.3, -74.5))
         .width(5)
         .color(Color.GREEN));
     ....
    

    Note that getMapAsync() is the new preferred way to get the map object. https://developers.google.com/maps/documentation/android-api/map

    Polyline details here - https://developers.google.com/android/reference/com/google/android/gms/maps/model/Polyline

提交回复
热议问题