简体   繁体   English

使用LatLng的Arraylist在两点之间绘制折线

[英]Drawing polylines between two points using an Arraylist of LatLng

I want to draw polylines between two points with using polylineoptions.addAll sending a parameter of ArrayList<LatLng> , but it doesn't show me the result. 我想使用polylineoptions.addAll发送两个参数ArrayList<LatLng>来在两点之间绘制多段线,但是它没有显示结果。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private ArrayList<LatLng> arrayPoints = new ArrayList<>();
    PolylineOptions polylineOptions=new PolylineOptions();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);


        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        mMap = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

        LatLng point=new LatLng(-35,151);
        LatLng point2=new LatLng(-40,151);

        polylineOptions.color(Color.RED);
        polylineOptions.width(3);
        arrayPoints.add(point);
        arrayPoints.add(point2);
        polylineOptions.addAll(arrayPoints);

    }

    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */

    @Override
    public void onMapReady(GoogleMap googleMap) 
    {

    }
}

Looks like you're not adding the polyline to the map 好像您没有在地图上添加折线

mMap.addPolyline(polylineOptions) mMap.addPolyline(polylineOptions)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM