Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android; MapView, how can I set default location?

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?

like image 589
Jimmy Avatar asked Aug 30 '10 11:08

Jimmy


People also ask

How do I change my default location on Google Maps Android?

Look to the top-left corner of the map, and click the three horizontal menu bars. From the options, select Your places. Next, click Home. Type the name of the location you want to set as your home address in the address field.

How do I get Google Maps to default to my current location?

Click the "Gear" icon and choose "Search Settings". Click "Location". Put in as detailed a location as you want. (A full address, a city and state, just a state, a country, etc.)


2 Answers

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

like image 60
matekm Avatar answered Sep 28 '22 04:09

matekm


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));
like image 27
soshial Avatar answered Sep 28 '22 03:09

soshial