Issue
I am displaying the user's current position and their intended destination using Google maps, MappingOverlayActivity and ItemizedOverlay.
What is the best way to firstly set the appropriate zoom level so that both locations are displayed on the map on the screen with the maximum area covered by the map, i.e rather than the current location being in the centre, having the centre being in the middle of the 2 points.. Also when the user's current location changes, how can I then recalulate and reset the appropriate zoom level to incorporate the new current location.
Solution
You use methods from MapController
(which you obtain using mapView.getController()
).
Specifically animateTo
(or moveTo
), and zoomToSpan
.
Assuming you have two GeoPoints
GeoPoint current;
GeoPoint destination;
do something like this
mapController.zoomToSpan(Math.abs(current.getLatitudeE6() - destination.getLatitudeE6()), Math.abs(current.getLongitudeE6() - destination.getLongitudeE6());
mapController.animateTo(new GeoPoint((current.getLatitudeE6() + destination.getLatitudeE6())/2, (current.getLongitudeE6() + destination.getLongitudeE6())/2));
so you calculate the span (difference) and center (average) of the points.
Answered By - skynet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.