Zoom Here Maps To Show All Markers Android
Solution 1:
Same thing I achieved using this.
valgeoCoordinateList= ArrayList<GeoCoordinate>()
valgeoBoundingBox= GeoBoundingBox.getBoundingBoxContainingGeoCoordinates(geoCoordinateList)
map.zoomTo(geoBoundingBox, Map.Animation.LINEAR, Map.MOVE_PRESERVE_TILT)
Solution 2:
You have to use the CameraUpdate class to do (probably) all programmatic map movements.
To do this, first calculate the bounds of all the markers like below:
LatLngBounds.Builderbuilder=newLatLngBounds.Builder();
//All Marker List to get Positionfor (Marker marker : markers) {
builder.include(marker.getPosition());
}
//Create Latlong Bounds.LatLngBoundsbounds= builder.build();
Then obtain a movement description object by using the factory: CameraUpdateFactory lime below :
intpadding=0; // offset from edges of the map in pixelsCameraUpdatecu= CameraUpdateFactory.newLatLngBounds(bounds, padding);
Now we can use that in Map like below:
googleMap.moveCamera(cu);
Solution 3:
You can use LatLngBounds.Builder() to make multiple markers to viewable under map.
It has a method include, which allow you to add multiple LAT LNG locations.
val bounds: LatLngBounds = locatebuilder.build() // locatebuilder is LatLngBounds.Builderval padding = 200// offset from edges of the map in pixelsval cu = CameraUpdateFactory.newLatLngBounds(bounds, padding)
mMap!!.animateCamera(cu)
EDIT
Make a new list of markers when you're adding it inside map
for (mark in markers) { // markers is a list of markers added in the map
locatebuilder.include(mark.position)
}
Solution 4:
According this issue: https://github.com/heremaps/here-android-sdk-examples/issues/176 you need to zoom like this:
privatevoidnavigateToMapMarkers(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.doubleminLat=90.0d;
doubleminLon=180.0d;
doublemaxLat= -90.0d;
doublemaxLon= -180.0d;
for (MapMarker marker : markers) {
GeoCoordinatecoordinate= marker.getCoordinate();
doublelatitude= coordinate.getLatitude();
doublelongitude= coordinate.getLongitude();
minLat = Math.min(minLat, latitude);
minLon = Math.min(minLon, longitude);
maxLat = Math.max(maxLat, latitude);
maxLon = Math.max(maxLon, longitude);
}
GeoBoundingBoxbox=newGeoBoundingBox(newGeoCoordinate(maxLat, minLon),
newGeoCoordinate(minLat, maxLon));
ViewRectviewRect=newViewRect(padding, padding, m_map.getWidth() - padding * 2,
m_map.getHeight() - padding * 2);
m_map.zoomTo(box, viewRect, Map.Animation.LINEAR, Map.MOVE_PRESERVE_ORIENTATION);
}
Solution 5:
You need to set the padding on the map before you apply the zoom
// (left, Top, right, Bottom)
map.setPadding(100, 100, 800, 400)
then you create the GeoBoundingBox and implement the zoom, or if you are getting a calculated route then you can get it in this way:
routeResult.route.boundingBox?.let { boundingBox ->
map.zoomTo(boundingBox, Map.Animation.BOW, Map.MOVE_PRESERVE_ORIENTATION)
}
I'm using HERE maps 3.18.2 version
Post a Comment for "Zoom Here Maps To Show All Markers Android"