我在地图上添加了5个引脚.如何告诉MapView尽可能缩放并保持所有引脚在视图中?
解决方法
我在最近的一个项目中使用了这种方法
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)); }
基本上它只是找到一个框的边界并将视图设置为包含边界的最近的视图
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。