我一直在谷歌和SO上研究这个,但我被卡住了,我想我错过了一些基本的东西。大多数examples我见过没有处理任意的mapWidth和单点,只是覆盖的跨度。Android:MapController.zoomToSpan:给定距离和中心点的距离
我有一个地图点数据库,一个MapView
和一个Geocoder
。我可以在我的应用程序中搜索邮政编码,并通过我的Geocoder
返回Address
。
使用此Address
,我可以构建一个GeoPoint
并搜索我的数据库并获取附近点的列表。问题来自于使用从返回的Address
点构建的跨度和到数据库中最近点的距离来尝试缩放到跨度。
我只希望跨度包含最近的两个点(如果可用)。下面是相关的代码:
Collections.sort(listingDisplay, mComparator);
listingDisplayAdapter.notifyDataSetChanged();
float spanWidth =0;
if (listingDisplay.size() > 1) {
spanWidth = (float) (2 * distanceFromPoint(listingDisplay.get(1),
current));
} else if (listingDisplay.size() == 1) {
spanWidth = (float) (2 * distanceFromPoint(listingDisplay.get(0),
current));
}
Log.v(TAG, "SpanWidth: " + spanWidth);
// Create span
int minLat = (int) (current.getLatitudeE6() - (spanWidth * 1E6)/2);
int maxLat = (int) (current.getLatitudeE6() + (spanWidth * 1E6)/2);
int minLong = (int) (current.getLongitudeE6() - (spanWidth * 1E6)/2);
int maxLong = (int) (current.getLongitudeE6() + (spanWidth * 1E6)/2);
// Zoom against span. This appears to create a very small region that doesn't encompass the points
mapController.setCenter(current);
mapController.zoomToSpan(Math.abs(minLat - maxLat), Math.abs(minLong - maxLong));
ListingDisplay
包含最近点的列表,比较,mComparator
对该列表进行排序与到最接近的位置我返回Address
(在GeoPoint
称为:current
)在列表的顶部。
然后,我根据最接近的值设置spanWidth
的值,并尝试从中找出跨度。
我的问题是,我该如何构建一个给定的距离和中心点的跨度?