Code example for CameraUpdate

0
 
 import com.google.android.gms.maps.CameraUpdate; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.model.LatLng; 
 
import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationManager; 
 
 
private LatLng getCurrentPosition(){
    // location details 
    locationManager     = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria   = new Criteria();
    String bestProvider = locationManager.getBestProvider(criteria, false);
 
    Location location   = locationManager.getLastKnownLocation(bestProvider);
    LatLng posLatLon    = new LatLng(location.getLatitude(), location.getLongitude());
    Toast.makeText(this, "position: "+ location.getLatitude() + "," + location.getLongitude(), Toast.LENGTH_SHORT).show();
    return posLatLon;
} 
 
private LatLng showCurrentPosition(GoogleMap map){
    LatLng posLatLon    = getCurrentPosition();
    CameraUpdate cam    = CameraUpdateFactory.newLatLngZoom(posLatLon, 12.0f);
    mMap.moveCamera(cam);
    return posLatLon;
}