Reputation: 1547
I'm trying to set the bounds on the mapview that I'm working with, so I'm always centered a certain way, and I can also see a full set of information based on the view. Basically I'll get a GPS coordinate for the center point, and then I'll get another value, say .9, which is the difference in the x/y of the current GPS spot that needs to be present in the current view. Example
Center-point: 37.777125, -12.2419644 (San Francisco)
Difference: .9
So the view would need to be
Top-Left: 36.877125, -13.1419644
Bottom-Right: 38.677125, -11.3419644
Is there a way to set the map view's bounds in this way?
Upvotes: 1
Views: 271
Reputation: 20944
It is. There is an interface in mapView's controller - zoomToSpan(long, long)
.
What you need is to do the following:
long latSpan = Math.abs(startLat - endLat);
long lonSpan = Math.abs(startLon - endLon);
mapView.getController().zoomToSpan(latSpan, lonSpan);
Where startLat
, endLat
, startLon
, endLon
- your calculated boundaries
Upvotes: 2