使用折线和arraylist在地图中添加多个点

use*_*388 2 android android-maps-v2

如何在谷歌地图中绘制多个纬度和经度坐标的折线.我需要动态绘制至少20组纬度和经度的折线.

use*_*968 6

使用折线和arraylist在地图中添加多个点

ArrayList<LatLng> coordList = new ArrayList<LatLng>();

// Adding points to ArrayList
coordList.add(new LatLng(0, 0);
coordList.add(new LatLng(1, 1);
coordList.add(new LatLng(2, 2);
// etc...

// Find map fragment. This line work only with support library
GoogleMap gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

PolylineOptions polylineOptions = new PolylineOptions();

// Create polyline options with existing LatLng ArrayList
polylineOptions.addAll(coordList);
polylineOptions
 .width(5)
 .color(Color.RED);

// Adding multiple points in map using polyline and arraylist
gMap.addPolyline(polylineOptions);
Run Code Online (Sandbox Code Playgroud)


kri*_*ant 5

Android文档中的示例:

   GoogleMap map;
   // ... get a map.
   // Add a thin red line from London to New York.
   Polyline line = map.addPolyline(new PolylineOptions()
     .add(new LatLng(51.5, -0.1), new LatLng(40.7, -74.0))
     .width(5)
     .color(Color.RED));
Run Code Online (Sandbox Code Playgroud)

只要.add你需要多次打电话.