Android的地图缩放显示全部销 [英] Android Map Zoom to Show all Pins
本文介绍了Android的地图缩放显示全部销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有5个管脚添加到地图。我怎么能告诉的MapView放大尽可能并保持所有引脚的看法?
I have 5 pins added to a map. How can I tell the MapView to zoom as much as possible and keep all pins in view?
推荐答案
我在我最近的项目中使用这个方法
I used this method in a recent project of mine
public void centerOverlays() {
int minLat = 81 * MapStoresController.MAP_SCALE;
int maxLat = -81 * MapStoresController.MAP_SCALE;
int minLon = 181 * MapStoresController.MAP_SCALE;
int maxLon = -181 * MapStoresController.MAP_SCALE;
for (int i = 0; i < overlayItems.size(); i++) {
Store s = overlayItems.getItem(i).getStore();
minLat = (int) ((minLat > (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE : minLat);
maxLat = (int) ((maxLat < (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE : maxLat);
minLon = (int) ((minLon > (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLongitude() * MapStoresController.MAP_SCALE : minLon);
maxLon = (int) ((maxLon < (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? .getLocation().getLongitude() * MapStoresController.MAP_SCALE : maxLon);
}
GeoPoint gp = controller.getUserLocation();
minLat = (minLat > gp.getLatitudeE6()) ? gp.getLatitudeE6() : minLat;
maxLat = (maxLat < gp.getLatitudeE6()) ? gp.getLatitudeE6() : maxLat;
minLon = (minLon > gp.getLongitudeE6()) ? gp.getLongitudeE6() : minLon;
maxLon = (maxLon < gp.getLongitudeE6()) ? gp.getLongitudeE6() : maxLon;
mapView.getController().zoomToSpan((maxLat - minLat), (maxLon - minLon));
mapView.getController().animateTo(new GeoPoint((maxLat + minLat) / 2, (maxLon + minLon) / 2));
}
基本上它只是发现了一个盒子的边界并设置视图以最近的一个,它包括的边界
Basically it just finds the bounds of a box and sets the view to the closest one that encompasses the bounds
这篇关于Android的地图缩放显示全部销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文