- Zoom到某個位置
原本的程式如下:
... MapController controller = _map_view.getController(); GeoPoint geoPoint = MyTracksUtils.getGeoPoint(currentLocation); controller.animateTo(geoPoint); ...
v2的程式如下,記得setMyLocationEnabled()要設成true:
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(my_location.getLatitude(), my_location.getLongitude())); CameraUpdate zoom=CameraUpdateFactory.zoomTo(15); getMap().moveCamera(center); getMap().animateCamera(zoom); getMap().setMyLocationEnabled(true);
- Zoom到某個區域
v1要自己算出中心點,然後求出zoom level。
int latSpanE6 = track.getTop() - track.getBottom(); int lonSpanE6 = track.getRight() - track.getLeft(); if (latSpanE6 > 0 && latSpanE6 < 180E6 && lonSpanE6 > 0 && lonSpanE6 < 180E6) { GeoPoint center = new GeoPoint( track.getBottom() + latSpanE6 / 2, track.getLeft() + lonSpanE6 / 2); if (MyTracksUtils.isValidGeoPoint(center)) { _map_view.getController().setCenter(center); _map_view.getController().zoomToSpan(latSpanE6, lonSpanE6); } }
v2反而比較簡單了。
LatLngBounds llb = new LatLngBounds( new LatLng(((double)track.getBottom())/1E6, ((double)track.getLeft())/1E6), new LatLng(((double)track.getTop())/1E6, ((double)track.getRight())/1E6)); CameraUpdate bound= CameraUpdateFactory.newLatLngBounds(llb, 0); getMap().moveCamera(bound);
沒有留言:
張貼留言