geotracking我跟着這裏的例子:How to set screen zoom by geopoints?OSM MapView類:顯示所有geopoints從屏幕
但我的問題是,我的路線是在MapView的非常小的。它應該在邊界附近結束。
這是它的外觀與下面的代碼:
private void centerMap(ArrayList<GeoPoint> waypoints) {
GeoPoint[] geoPoints = new GeoPoint[waypoints.size()];
for(int i = 0; i<waypoints.size(); i++) {
geoPoints[i] = waypoints.get(i);
}
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;
//for (Point point : twoPoints) {
for(GeoPoint point: geoPoints){
int lat = (int) (point.getLatitude() * 1E6);
int lon = (int) (point.getLongitude() * 1E6);
maxLat = Math.max(lat, maxLat);
minLat = Math.min(lat, minLat);
maxLon = Math.max(lon, maxLon);
minLon = Math.min(lon, minLon);
}
mapView.getController().zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
mapView.getController().setCenter(new GeoPoint((maxLat + minLat)/2, (maxLon + minLon)/2));
}
請注意'(maxLat + minLat)/ 2'可能溢出。改用'maxLat - (maxLat - minLat)/ 2'。經度也是如此。 – scai