paulrehkugler
paulrehkugler

Reputation: 3271

Adding padding to MapViewController.zoomToSpan()

I have a MapView, and I call getController().zoomToSpan() on it. My problem with zoomToSpan() is that I want to have a consistent (for example, 15dp) padding outside of the map pins so that they may be selected without needing the user to pinch to zoom out. Currently I am populating zoomToSpan() with the minimum/maximum long/lat of the map pins, so the ones on the edges aren't immediately visible or selectable.

I've considered using a fixed long/lat padding, but I have no guarantee that the map pins won't be excessively close or far away from each other. So although a fixed long/lat padding may work for most cases, it won't work for all cases.

This is how I am currently setting zoomToPan():

mapView.getController().zoomToSpan(MapPoint.convertToGeoPoint(Math.abs(fMinLat - fMaxLat)), MapPoint.convertToGeoPoint(Math.abs(fMinLong - fMaxLong)));

This is an idea I had on how to set it, but I am not sure if it actually solves the problem, or if there is a better way to do it:

mapView.getController().zoomToSpan(MapPoint.convertToGeoPoint((float) (Math.abs(fMinLat-fMaxLat) + (Math.abs(fMaxLat - fMaxLat)) * 0.5)), MapPoint.convertToGeoPoint((float) (Math.abs(fMinLong-fMaxLong) + (Math.abs(fMinLong - fMaxLong) * 0.5))));

I've already checked out these questions, but I'm past the point of making it work; I just want to make it polished: zoomToSpan implementation problem, and Calculating zoomToSpan() degrees based on min/max lat/lng to be in the mapView.

Upvotes: 0

Views: 178

Answers (1)

Luis
Luis

Reputation: 12048

Your solution should work fine. Just note that you have a typo in "(Math.abs(fMaxLat - fMaxLat)) * 0.5)". You are using twice "fMaxLat".

You could write it in a simpler form:

mapView.getController().zoomToSpan((int)(Math.abs(fMinLat-fMaxLat) * 1.5), (int)(Math.abs(fMinLong-fMaxLong) * 1.5));

Then you can try different multiplying values between 1.0 and 1.99, to see what better achieve your expectations.

Also keep in mind that zoom always change in steps (is not progressive) of powers of 2, meaning it will double the zoom or it will reduce to half. The final result achieved will vary with different points in the map, which can fit closely to a zoom value and very distante from the edge on previous one.

Upvotes: 1

Related Questions