【发布时间】:2012-02-24 21:47:38
【问题描述】:
我一直在 Google 和 SO 上对此进行研究,但我被困住了,我认为我缺少一些基本的东西。我见过的大多数 examples 不处理任意 mapWidth 和单个点,只是覆盖的跨度。
我有一个地图点数据库,一个MapView 和一个Geocoder。我可以在我的应用中搜索邮政编码,然后我的Geocoder 返回一个Address。
使用这个Address,我可以构建一个GeoPoint 并搜索我的数据库并获取附近点的列表。问题来自尝试使用从返回的Address 点和到数据库中最近点的距离构造的跨度来缩放ToSpan。
我只希望跨度包含最近的两个点(如果可用)。以下是相关代码:
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的值,并尝试从中找出跨度。
我的问题是,如何从给定的距离和中心点构建跨度?
【问题讨论】:
标签: android android-maps