Reputation: 29
I'm developing an app for android which is supposed to give directions using OpenStreetMap (OSM).
My problem is that I can't seem to find the proper API functions to fix the zooming level of the map when the user enters the source and the destination address.
So far, the map displayed only shows parts of the calculated path.
I'd like to fix the zooming level such that the entire path fits within the screen.
Could someone give me a hint where I can find proper documentation?
My code
This my code:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/buttonSearchDest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="0"
android:text="@string/GetDirection"/>
</LinearLayout>
protected void onPostExecute(List foundAdresses) {
if (foundAdresses == null) {
Toast.makeText(getApplicationContext(), "Geocoding error", Toast.LENGTH_SHORT).show();
} else if (foundAdresses.size() == 0) {
Toast.makeText(getApplicationContext(), "Address not found.", Toast.LENGTH_SHORT).show();
} else {
Address address = foundAdresses.get(0);
String addressDisplayName = address.getExtras().getString("display_name");
if (mIndex == START_INDEX){
startPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerStart = updateItineraryMarker(markerStart, startPoint, START_INDEX,
R.string.departure, R.drawable.marker_departure, -1, addressDisplayName);
map.getController().setCenter(startPoint);
} else if (mIndex == DEST_INDEX){
destinationPoint = new GeoPoint(address.getLatitude(), address.getLongitude());
markerDestination = updateItineraryMarker(markerDestination, destinationPoint, DEST_INDEX,
R.string.destination, R.drawable.marker_destination, -1, addressDisplayName);
map.getController().setCenter(destinationPoint);
}
getRoadAsync();
}
}
}
Upvotes: 0
Views: 1372
Reputation: 85
Perhaps if you could somehow retrieve the total distance from point A and point B, then based on that distance retrieved associate it to a certain zoom level and then animate the mapview to be in the center.
Let's say a straight line between Point A and Point B is...
10 Kilometer. And you know that 10 KM is sufficiently displayed on your mapview at zoom level... 16.
So you what you might consider doing is:
mapView.getController().setZoom(16);
mapView.getController().animateTo(myPoint1);
Where myPoint1 is the center point between Point A and B, so that you can view the whole route.
I personally am new to android development so I don't know the difference between animateTo and setCenter... But I hope my answer somehow jogs ideas in your head as to how you could solve your problem?
Upvotes: 1