2

複数の緯度と経度の座標の Google マップでポリラインを描画する方法。少なくとも 20 セットの緯度と経度のポリラインを動的に描画する必要があります。

4

4 に答える 4

7

polyline と 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);
于 2014-09-22T16:11:36.687 に答える
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));

.add必要な回数だけ電話してください。

于 2013-08-16T04:52:59.103 に答える
0

ポイントの配列を反復処理し、座標ごとに新しい LatLng をポリライン オプションに追加してから、ループの後にポリライン オプションをポリラインに追加できます。

 val from = LatLng(it.data[0].lat, it.data[0].lng)
                            val to = LatLng(it.data.last().lat, it.data.last().lng)
                            map.addMarker(MarkerOptions().position(from).title("pickup location"))
                            map.addMarker(MarkerOptions().position(to).title("destination location"))
                            map.animateCamera(CameraUpdateFactory.newLatLngZoom(from, 13f)) 
                            var polylineOptions = PolylineOptions()
                            for (i in it.data){
                                polylineOptions.add(LatLng(i.lat, i.lng))
                            }

                            polylineOptions.width(5f).color(Color.RED)
                            map.addPolyline(
                                polylineOptions
                            )
于 2019-12-31T10:56:12.220 に答える