我如何计算的跟踪路线缩放级别完全适合于地图(屏幕)的看法?我有根/整条赛道的起点和终点/在经度/纬度的位置,我能计算出与输入参数表的缩放级别,但有多少米,我需要设置?我想在地图上显示的记录轨道。我发现赛道,但不适合的地图。
How can I calculate the zoom level for the tracked route to fit perfectly to the view of map(screen)? I have the start and end point of root/whole track/ in Lon/Lat position, I able to calculate the zoom level with input parameter meter, but how many meters need I set? I would like to show the logged track on the map. I showed the track but doesn't fit into map.
您可以通过这个code段变焦,只需要传递的起点和终点的GeoPoint在列表中。如果你有2点多它也可以。
You can set the zoom with this code snippet, just need to pass the starting and ending geopoint in a list. If you have more than 2 points it also works.
private void fixZoom(MapController controller, List <GeoPoint> items){
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;
for (GeoPoint item : items)
{
int lat = item.getLatitudeE6();
int lon = item.getLongitudeE6();
maxLat = Math.max(lat, maxLat);
minLat = Math.min(lat, minLat);
maxLon = Math.max(lon, maxLon);
minLon = Math.min(lon, minLon);
}
controller.zoomToSpan((int) (Math.abs(maxLat - minLat) * 1.1), (int)(Math.abs(maxLon - minLon) * 1.1)); //1.1 to have some padding on the edges.
controller.animateTo(new GeoPoint( (maxLat + minLat)/2,(maxLon + minLon)/2 )); //so the center is positioned just in the middle
}
希望有所帮助。