Android Map缩放以显示所有引脚

前端之家收集整理的这篇文章主要介绍了Android Map缩放以显示所有引脚前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在地图上添加了5个引脚.如何告诉MapView尽可能缩放并保持所有引脚在视图中?

解决方法

我在最近的一个项目中使用了这种方法
  1. public void centerOverlays() {
  2. int minLat = 81 * MapStoresController.MAP_SCALE;
  3. int maxLat = -81 * MapStoresController.MAP_SCALE;
  4. int minLon = 181 * MapStoresController.MAP_SCALE;
  5. int maxLon = -181 * MapStoresController.MAP_SCALE;
  6.  
  7. for (int i = 0; i < overlayItems.size(); i++) {
  8. Store s = overlayItems.getItem(i).getStore();
  9. minLat = (int) ((minLat > (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE : minLat);
  10. maxLat = (int) ((maxLat < (s.getLocation().getLatitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLatitude() * MapStoresController.MAP_SCALE : maxLat);
  11. minLon = (int) ((minLon > (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? s.getLocation().getLongitude() * MapStoresController.MAP_SCALE : minLon);
  12. maxLon = (int) ((maxLon < (s.getLocation().getLongitude() * MapStoresController.MAP_SCALE)) ? .getLocation().getLongitude() * MapStoresController.MAP_SCALE : maxLon);
  13. }
  14.  
  15. GeoPoint gp = controller.getUserLocation();
  16.  
  17. minLat = (minLat > gp.getLatitudeE6()) ? gp.getLatitudeE6() : minLat;
  18. maxLat = (maxLat < gp.getLatitudeE6()) ? gp.getLatitudeE6() : maxLat;
  19. minLon = (minLon > gp.getLongitudeE6()) ? gp.getLongitudeE6() : minLon;
  20. maxLon = (maxLon < gp.getLongitudeE6()) ? gp.getLongitudeE6() : maxLon;
  21.  
  22. mapView.getController().zoomToSpan((maxLat - minLat),(maxLon - minLon));
  23. mapView.getController().animateTo(new GeoPoint((maxLat + minLat) / 2,(maxLon + minLon) / 2));
  24. }

基本上它只是找到一个框的边界并将视图设置为包含边界的最近的视图

猜你在找的Android相关文章