2017-05-03 33 views
0

在我的android應用程序中,我在osmdroid中使用了路由和集羣,但是我無法像在google地圖中使用latlngbounds.builder一樣綁定LatLng。例如在谷歌地圖中使用osmdroid將lat lng與LatLngBounds綁定在一起

LatLng longlat = new LatLng(lat, log); 

LatLngBounds.Builder builder = new LatLngBounds.Builder(); 
builder.include(longlat); 

我想要做同樣的osmdroid。

+0

你在說osmdroid嗎?請至少提及您正在使用的圖書館。 – scai

+0

是的,我正在談論osmdroid – srk

回答

1

谷歌地圖LatLngBounds成爲osmdroid中的BoundingBox(或多或少)。

它沒有直接等同於LatLngBounds.including方法(是的,可能是一個好主意來實現這一個)。

但是BoundingBox.fromGeoPoints涵蓋了很多需求。

0
{ 
IGeoPoint screenTopLeft = mapView.getProjection().fromPixels(0, 0); 
      IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0); 
      IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight()); 
      List<IGeoPoint> iGeoPoints = new ArrayList<>(); 
      iGeoPoints.add(screenTopRight); 
      iGeoPoints.add(screenTopLeft); 
      iGeoPoints.add(screenBottomLeft); 
      BoundingBox boundingBox = BoundingBox.fromGeoPoints(iGeoPoints); 
      if (boundingBox.contains(currentLocation.getLatitude(), currentLocation.getLongitude())) { 
       return true; 
      } else { 
       return false; 
      } 
     } 

這將檢查當前位置是否受到束縛。

相關問題