安卓;地图视图,如何设置默认位置?

16

在Android中使用MapView,我如何设置默认位置,以便每次加载此应用程序时,它可以自动将地图中心/缩放到伦敦?

2个回答

40

首先,获取给定地图的控制器:

MapController myMapController = myMapView.getController();

然后调用:

myMapController.setCenter(new GeoPoint())

这将在给定的GeoPoint上设置地图的中心点。
有关更多信息,请参阅MapViewMapController的文档。

1
对于新的 Google 地图 API,您需要执行以下操作:

mapFragment.getMapAsync(this::setUpMaps);

setUpMaps(GoogleMap googleMap) 中,您应该将相机移动到默认位置:
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, zoom));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接