2015-01-12 73 views
0

我需要解釋如何使用CameraUpdateFactory。我的應用程序在屏幕上繪製一條路線,我需要集中此路線圖。然後獲取路線的邊界並嘗試設置縮放。 但是,當我運行巨大的縮放,參考文檔說CameraUpdateFactory的最高縮放可能但這不是我所需要的。放大從谷歌地圖v2獲得的bouns路線android

  mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { 
      @Override 
      public void onMapLoaded() { 
       mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 6));    
      } 
     }); 

回答

1

Adjusting google map (api v2) zoom level in android

它的工作原理!

mMap.addMarker(new MarkerOptions().position(fromPosition).title(start_address)); 
    mMap.addMarker(new MarkerOptions().position(toPosition).title(end_address)); 

    com.google.android.gms.maps.model.LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); 
    boundsBuilder.include(fromPosition); 
    boundsBuilder.include(toPosition);    

    final LatLngBounds bounds = boundsBuilder.build(); 

    mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { 
      @Override 
      public void onMapLoaded() { 
       mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 12));    
      } 
     });