我正在使用osmdroid庫來渲染地圖。我有兩個間歇性變化的地理點,並希望org.osmdroid.views.MapView調整大小和平移,確保兩個點始終可見。我可以輕鬆地將地圖重新定位在兩者之間的中點,但是如何設置縮放級別以確保我的兩點可見?Osmdroid顯示兩個地理位置的最大縮放級別
UPDATE
//Getting pickup and destination latitude and longitude
GeoPoint pickupLocation = null;
if (tripRequest.getPickupLat() != null && tripRequest.getPickupLong() != null) {
pickupLocation = new GeoPoint(tripRequest.getPickupLat(), tripRequest.getPickupLong());
}
GeoPoint destinationLocation = null;
if (tripRequest.getDestinationLat() != null && tripRequest.getDestinationLong() != null) {
destinationLocation = new GeoPoint(tripRequest.getDestinationLat(), tripRequest.getDestinationLong());
}
if (destinationLocation != null && pickupLocation != null) {
//Adding destination marker to map
Marker destinationLocationMarker = new Marker(map);
destinationLocationMarker.setPosition(destinationLocation);
destinationLocationMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
destinationLocationMarker.setIcon(context.getResources().getDrawable(R.mipmap.pin_green_small));
map.getOverlays().add(destinationLocationMarker);
//Adding pickup marker to map
Marker pickupLocationMarker = new Marker(map);
pickupLocationMarker.setPosition(pickupLocation);
pickupLocationMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
pickupLocationMarker.setIcon(context.getResources().getDrawable(R.mipmap.pin_red_small));
map.getOverlays().add(pickupLocationMarker);
BoundingBox boundingBox = BoundingBox.fromGeoPoints(Arrays.asList(destinationLocation, pickupLocation));
mapController = map.getController();
mapController.setCenter(boundingBox.getCenter());
mapController.setZoom(10);// I need to set this zoom properly
touchListener = new TouchListener();
map.setOnTouchListener(touchListener);
感謝您的建議,我更新了我的代碼。我可以居中一個邊界框,但似乎無法在縮放中使用該邊界框。 –
我也嘗試過map.zoomToBoundingBox(boundingBox,false);但它不起作用。 –