使用LatLng的

时间:2015-12-02 16:07:07

标签: java android google-maps

我希望使用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) 
    {

    }
}

1 个答案:

答案 0 :(得分:0)

您似乎没有将折线添加到地图

  

mMap.addPolyline(的PolylineOptions)