use of com.here.android.mpa.common.ViewRect in project here-android-sdk-examples by heremaps.
the class MapFragmentView method navigateToMapMarkers.
private void navigateToMapMarkers(List<MapMarker> markers, int padding) {
// find max and min latitudes and longitudes in order to calculate
// geo bounding box so then we can map.zoomTo(geoBox, ...) to it.
double minLat = 90.0d;
double minLon = 180.0d;
double maxLat = -90.0d;
double maxLon = -180.0d;
for (MapMarker marker : markers) {
GeoCoordinate coordinate = marker.getCoordinate();
double latitude = coordinate.getLatitude();
double longitude = coordinate.getLongitude();
minLat = Math.min(minLat, latitude);
minLon = Math.min(minLon, longitude);
maxLat = Math.max(maxLat, latitude);
maxLon = Math.max(maxLon, longitude);
}
GeoBoundingBox box = new GeoBoundingBox(new GeoCoordinate(maxLat, minLon), new GeoCoordinate(minLat, maxLon));
ViewRect viewRect = new ViewRect(padding, padding, m_map.getWidth() - padding * 2, m_map.getHeight() - padding * 2);
m_map.zoomTo(box, viewRect, Map.Animation.LINEAR, Map.MOVE_PRESERVE_ORIENTATION);
}
Aggregations