如果有时间加了很多overlayItem,由于缩放问题 有些不能显示为了全部显示
- 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));
- }
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)); }
2.
- /**
- * Fits the map with the passed in points so all points are visible.
- * @param mapController MapView controller
- * @param points list of points you want the map to contain
- */
- private static void fitPoints(MapController mapController, List points) {
- // set min and max for two points
- int nwLat = -90 * 1000000;
- int nwLng = 180 * 1000000;
- int seLat = 90 * 1000000;
- int seLng = -180 * 1000000;
- // find bounding lats and lngs
- for (GeoPoint point : points) {
- nwLat = Math.max(nwLat, point.getLatitudeE6());
- nwLng = Math.min(nwLng, point.getLongitudeE6());
- seLat = Math.min(seLat, point.getLatitudeE6());
- seLng = Math.max(seLng, point.getLongitudeE6());
- }
- GeoPoint center = new GeoPoint((nwLat + seLat) / 2, (nwLng + seLng) / 2);
- // add padding in each direction
- int spanLatDelta = (int) (Math.abs(nwLat - seLat) * 1.1);
- int spanLngDelta = (int) (Math.abs(seLng - nwLng) * 1.1);
- // fit map to points
- mapController.animateTo(center);
- mapController.zoomToSpan(spanLatDelta, spanLngDelta);
- }