I'm using Java with ArcGIS 100.1.0—ArcGIS Runtime SDK for Android. I have a number of locations(Point s) on the map, after I added all the markers as graphics (on a graphic overlay), I want to zoom the map to be able to see all of them with the zoom adjusting to fit them on the map. I tried drawing a polygon and getting its envelope. And used
Envelope envelope = graphicsOverlay.getExtent();
mapView.setViewInsets( envelope.getXMin() - DEFAULT_PADDING,
envelope.getYMax() + DEFAULT_PADDING,
envelope.getXMax() + DEFAULT_PADDING,
envelope.getYMin() - DEFAULT_PADDING);
and I get a very bad zoom (too close) and not displaying the whole graphics.
Then I tried :
//1-we create a polygon out of these locations
PointCollection corners = new PointCollection(spatialReference);
for(Point point : points){
corners.add(point.getX(),point.getY());
}
Polygon polygon = new Polygon(corners);
//2- we get the extent
Envelope envelope = polygon.getExtent();
mapView.setViewInsets( envelope.getXMin() - DEFAULT_PADDING,
envelope.getYMax() + DEFAULT_PADDING,
envelope.getXMax() + DEFAULT_PADDING,
envelope.getYMin() - DEFAULT_PADDING);
I still have the same unwanted result. Does anyone has and answer? Coming from Google Maps API v2 Android, I used to use the latlongBound to achieve this behavior.
Another solution would be to be able to evaluate the scale that I should apply to the mapview once I am able to get the extent of the overlay on which my markers/graphics (coming from Google Maps) are displayed. Does anyone know how to get that scale?