2015-12-02 84 views
0

我想在两点之间使用polylineoptions.addAll发送参数ArrayList<LatLng>来绘制多段线,但它不会显示结果。使用LatLng的Arraylist在两点之间绘制多段线

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) 
    { 

    } 
} 

回答

0

你看上去不添加折线到地图

mMap.addPolyline(的PolylineOptions)

+0

啊非常感谢你。 – user3744110

相关问题