开发者

Android; MapView, how can I set default location?

开发者 https://www.devze.com 2023-01-13 10:41 出处:网络
Using the MapView in android, how can I set a default location, so that everytime I load开发者_运维问答 up this application, it automatically centers/zooms location in on London?Firstly, get the contr

Using the MapView in android, how can I set a default location, so that everytime I load开发者_运维问答 up this application, it automatically centers/zooms location in on London?


Firstly, get the controller for the given map:

MapController myMapController = myMapView.getController();

and then call:

myMapController.setCenter(new GeoPoint())

This will set the center of the map on the given GeoPoint.

See docs for MapView and MapController for more info


For new Google Maps API you need to do this:

mapFragment.getMapAsync(this::setUpMaps);

And inside setUpMaps(GoogleMap googleMap) you should move camera to your default location:

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, zoom));
0

精彩评论

暂无评论...
验证码 换一张
取 消