gpt4 book ai didi

android - Osmdroid 最大缩放级别显示两个地理位置

转载 作者:行者123 更新时间:2023-11-29 16:54:14 26 4
gpt4 key购买 nike

我正在使用 osmdroid 库来渲染 map 。我有两个间歇性变化的地理点,并希望 org.osmdroid.views.MapView 调整大小和转换以确保两个点始终可见。我可以轻松地将 map 重新​​居中于两者之间的中间点,但如何设置缩放级别以确保我的两个点可见?

更新

  //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);

最佳答案

使用 zoomToBoundingBox。它应该可以工作,如果没有问题,将在其他地方。

尝试:

map.zoomToBoundingBox(boundingBox, false);
map.invalidate();

如果这仍然不起作用,请检查此响应: zoom mapView to a certain bounding box on osmdroid

如果您真的想自己计算缩放比例,您总能在 source code of zoomToBoundingBox method 中找到灵感。并修改计算以满足您的需要。

关于android - Osmdroid 最大缩放级别显示两个地理位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45434963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com