0

我正在嘗試爲我在地圖上的點執行路線指示,爲此我正在使用Polyline,問題在於,我設法連接了地圖的2個點,但是我有一個8點的LatLng數組,我將如何連接所有點?:駕駛模式的路線指示

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 


     setContentView(R.layout.maps); 


     ArrayList<LatLng> coordList = new ArrayList<LatLng>(); 
     ArrayList<String> nomes = new ArrayList<String>(); 
     try { 

      Bundle parametros = getIntent().getExtras(); 
      rm_IdViagem = parametros.getString("id_viagem"); 

      Repositorio ca = new Repositorio(this); 
      mViagemModel = ca.getViagemPorId(Integer.valueOf(rm_IdViagem)); 

      Repositorio cl = new Repositorio(this); 
      mClienteModel = cl.getClientesViagem(Integer.valueOf(rm_IdViagem)); 


      if(mClienteModel != null) { 

       for (int i = 0; i < mClienteModel.size(); i++) { 


        Repositorio mRepositorio = new Repositorio(this); 
        mEnderecoModel = mRepositorio.getListaEnderecosDoCliente(Integer.valueOf(mClienteModel.get(i).getClientes_id())); 


        for (int j = 0; j < mEnderecoModel.size(); j++) { 
         // Loading map 
         initilizeMap(); 
         // Changing map type 
         googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
         // googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
         // googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
         // googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); 
         // googleMap.setMapType(GoogleMap.MAP_TYPE_NONE); 

         // Showing/hiding your current location 
         googleMap.setMyLocationEnabled(true); 

         // Enable/Disable zooming controls 
         googleMap.getUiSettings().setZoomControlsEnabled(true); 

         // Enable/Disable my location button 
         googleMap.getUiSettings().setMyLocationButtonEnabled(true); 

         // Enable/Disable Compass icon 
         googleMap.getUiSettings().setCompassEnabled(true); 

         // Enable/Disable Rotate gesture 
         googleMap.getUiSettings().setRotateGesturesEnabled(true); 

         // Enable/Disable zooming functionality 
         googleMap.getUiSettings().setZoomGesturesEnabled(true); 


         final float latitude = Float.parseFloat(mEnderecoModel.get(j).getLatitude()); 
         final float longitude = Float.parseFloat(mEnderecoModel.get(j).getLongitude()); 



         nomes.add(mClienteModel.get(i).getNome()); 


         coordList.add(new LatLng(latitude, longitude)); 

         googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 5)); 



         mClusterManager = new ClusterManager<MyItem>(MapaViagem.this, googleMap); 


         mClusterManager.setRenderer(new MyClusterRenderer(MapaViagem.this, googleMap, mClusterManager)); 

         googleMap.setOnCameraChangeListener(mClusterManager); 
         googleMap.setOnMarkerClickListener(mClusterManager); 

         //mClusterManager.setAlgorithm(new GridBasedAlgorithm<MyItem>()); 




         addItems(coordList, nomes); 


         mClusterManager.cluster(); 





       } 


      } 
     } 


    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 


public class MyClusterRenderer extends DefaultClusterRenderer<MyItem> { 

    public MyClusterRenderer(Context context, GoogleMap map, 
          ClusterManager<MyItem> clusterManager) { 
     super(context, map, clusterManager); 
    } 

    @Override 
    protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) { 
     super.onBeforeClusterItemRendered(item, markerOptions); 

     markerOptions.title(String.valueOf(item.getName())); 
    } 

    @Override 
    protected void onClusterItemRendered(MyItem clusterItem, Marker marker) { 
     super.onClusterItemRendered(clusterItem, marker); 



     //here you have access to the marker itself 
    } 

    @Override 
    protected boolean shouldRenderAsCluster(Cluster<MyItem> cluster) { 
     return cluster.getSize() > 1; 
    } 



} 

回答