2017-05-24 20 views
0

我有一個已經正確初始化的GoogleMap(精簡模式)對象。它適用於單個標記,並使用CameraUpdate和newLatLngZoom重點關注適當的區域。LatLngBounds和CameraUpdate沒有放大

但是,當涉及到添加兩個標記,並且使用LatLngBounds使地圖保持在視圖中時,所有事情都會變得焦躁不安。地圖縮小顯示整個大陸,兩個標記相互疊加(與多段線一起)。

請假設從皮卡和目的地的數據是正確的

這裏是我的代碼:

googleMap.addMarker(new MarkerOptions() 
        .position(pickup) 
        .title(job.getPickupAddress())); 

      googleMap.addMarker(new MarkerOptions() 
        .position(destination) 
        .title(job.getDestinationAddress()) 
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))); 

      CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(new LatLngBounds.Builder().include(pickup).include(destination).build(), 0); 
      googleMap.moveCamera(cameraUpdate); 

      String pickupLatLng = job.getPickupLatLong().latitude + "," + job.getPickupLatLong().longitude; 
      String destinationLatLng = job.getDestinationLatLong().latitude + "," + job.getDestinationLatLong().longitude; 
      plotPolyLines(pickupLatLng, destinationLatLng); 

輸出:

The output

回答

0

嘗試改變線

googleMap.moveCamera(cameraUpdate); 

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f)); 

的建議在How do I set default location and Zoom level for google map api v2? 或使用

map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null); 

這應該移動攝像機更貼近您的標記。

+0

但是,這不會使相機對準兩個標記。使用範圍的重點在於兩個標記都可以在視圖中顯示。 – Asim

相關問題