how to open up a map of a particular city using google APIs in android

509 views Asked by At

I have been able to open up a map of the world through code and mark a few places. However, I always have to zoom down to the city, which takes a little while. Is there any way to directly open up a map of a particular city?

2

There are 2 answers

0
Mostafa Gazar On

You can use moveCamera with your last stored location (lat, lng and maybe zoomLevel too) for example.

final LatLng location = new LatLng(..., ...);// Loaded from SharedPreferences maybe.

// Move the camera to location with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 15));
0
Hafizh Herdi On

You can use this sample code to animate the map directly to your city coordinate (lat, lng) and automatically zooming out to specified level :

// Set desired lat lng location, and zoom level (for example 10)
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(locationCity.getLatitude(), locationCity.getLongitude()), 10);
// Move the camera to location
gMap.animateCamera(cameraUpdate);