Skip to content

Instantly share code, notes, and snippets.

@alorma
Created February 13, 2015 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alorma/11d787209272162fb92a to your computer and use it in GitHub Desktop.
Save alorma/11d787209272162fb92a to your computer and use it in GitHub Desktop.
SupportMapFragment mapFragment;
if (savedInstanceState == null) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria cri = new Criteria();
String bbb = locationManager.getBestProvider(cri, true);
Location myLocation = locationManager.getLastKnownLocation(bbb);
if (myLocation != null) {
LatLng ll = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
GoogleMapOptions googleMapOptions = new GoogleMapOptions();
googleMapOptions.camera(CameraPosition.fromLatLngZoom(ll, 15));
mapFragment = SupportMapFragment.newInstance(googleMapOptions);
} else {
mapFragment = SupportMapFragment.newInstance();
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.map, mapFragment, "map");
ft.commit();
} else {
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag("map");
}
if (mapFragment != null) {
mapFragment.getMapAsync(this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment