问题描述
我显示用户的当前位置,并使用谷歌地图,MappingOverlayActivity和ItemizedOverlay预定目的地。
I am displaying the user's current position and their intended destination using Google maps, MappingOverlayActivity and ItemizedOverlay.
什么是先设置适当的缩放级别,以便这两个位置被显示在地图上的屏幕上与由地图,即,而不是当前位置在中心被覆盖的最大面积的最佳方式中,具有中心在2点的中间是..另外当用户的当前位置的变化,我怎么能那么recalulate并重新设置适当的缩放级别,以纳入新的当前位置。
What is the best way to firstly set the appropriate zoom level so that both locations are displayed on the map on the screen with the maximum area covered by the map, i.e rather than the current location being in the centre, having the centre being in the middle of the 2 points.. Also when the user's current location changes, how can I then recalulate and reset the appropriate zoom level to incorporate the new current location.
推荐答案
您使用从<一个方法href=\"http://$c$c.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapController.html\"相对=nofollow> MapController
(你获得使用 mapView.getController()
)
具体<一个href=\"http://$c$c.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapController.html#animateTo%28com.google.android.maps.GeoPoint%29\"相对=nofollow> animateTo
(或的moveTo
)和<一个href=\"http://$c$c.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapController.html#zoomToSpan%28int,%20int%29\"相对=nofollow> zoomToSpan
。
Specifically animateTo
(or moveTo
), and zoomToSpan
.
假设你有两个GeoPoints
Assuming you have two GeoPoints
GeoPoint current;
GeoPoint destination;
做这样的事情。
mapController.zoomToSpan(Math.abs(current.getLatitudeE6() - destination.getLatitudeE6()), Math.abs(current.getLongitudeE6() - destination.getLongitudeE6());
mapController.animateTo(new GeoPoint((current.getLatitudeE6() + destination.getLatitudeE6())/2, (current.getLongitudeE6() + destination.getLongitudeE6())/2));
所以你计算点的跨度(差)和中央(平均)。
so you calculate the span (difference) and center (average) of the points.
这篇关于Android的地图缩放级别的当前位置和目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!