Search in sources :

Example 1 with ViewRect

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);
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) ViewRect(com.here.android.mpa.common.ViewRect) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Aggregations

GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)1 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)1 ViewRect (com.here.android.mpa.common.ViewRect)1 MapMarker (com.here.android.mpa.mapping.MapMarker)1