简体   繁体   中英

Location query in Google maps in android

I have made an app utilizing Google Maps. I have added a marker of my current location in it. However, as soon as I open the app, I want it to zoom in to my location instead of showing the whole world at the 95302 23535919711008489 location first. How do I accomplish this?

Use animateCamera() as below

@Override
public void onLocationChanged(Location location) {
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
    map.animateCamera(cameraUpdate);
    locationManager.removeUpdates(this);
}

Please read the docs

  LatLng cameraLatLng = new LatLng(savedLat, savedLng); googleMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map)).getMap(); googleMap.animateCamera(CameraUpdateFactory .newLatLngZoom(cameraLatLng, 7)) 

savedLat, savedLng your current location longitude and latitude.You can change zoom number ( 7 ) to your fitting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM