title: Getting a Google maps activity in Android Studio to show current location
body: <p>Hey so I've searched a ton on this site and the internet for an answer to getting android studio to show my current location for an app I'm trying to create.  Each answer doesn't seem to help.  Here is my code and I'm not sure what I need to change. </p>
  
  <pre><code>import android.Manifest;
  import android.content.Context;
  import android.content.pm.PackageManager;
  import android.location.Criteria;
  import android.location.Location;
  import android.location.LocationManager;
  import android.location.LocationListener;
  import android.support.v4.app.ActivityCompat;
  import android.support.v4.app.FragmentActivity;
  import android.os.Bundle;
  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.OnMapReadyCallback;
  import com.google.android.gms.maps.SupportMapFragment;
  import com.google.android.gms.maps.model.LatLng;
  import com.google.android.gms.maps.model.MarkerOptions;
  
  public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
  
  
  
      private GoogleMap mMap;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_maps);
          setUpMapIfNeeded();
          // Obtain the SupportMapFragment and get notified when the map is ready to be used.
  
  
          LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
  
          Criteria criteria = new Criteria();
          criteria.setAccuracy(Criteria.ACCURACY_FINE);
          criteria.setPowerRequirement(Criteria.POWER_LOW);
          criteria.setAltitudeRequired(false);
          criteria.setBearingRequired(false);
          criteria.setSpeedRequired(false);
          criteria.setCostAllowed(true);
  
  
          String provider=locationManager.getBestProvider(criteria, true);
  
  
          if (locationManager != null) {
              if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                      || checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                  Location loc = locationManager.getLastKnownLocation(provider);
                  locationManager.requestLocationUpdates(provider, 60000, 10, locationListener);
              }
          }
      }
  
      private void updateWithNewLocation(Location loc) {
          if(loc != null) {
              double lng = loc.getLongitude();
              double lat = loc.getLatitude();
  
              LatLng location = new LatLng(lat,lng);
              mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
              CameraUpdate update = CameraUpdateFactory.newLatLngZoom(location, 20);
              mMap.animateCamera(update);
  
          }
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          setUpMapIfNeeded();
      }
  
      private final LocationListener locationListener = new LocationListener(){
  
  
          public void onChange(String provider, int status, Bundle extras) {
  
          }
          public void onProviderEnabled(String provider) {
          }
          public void onProviderDisabled(String provider) {
          }
  
          public void onLocationChanged(Location location) {
              updateWithNewLocation(location);
          }
  
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
  
          }
      };
  
      private void setUpMapIfNeeded() {
          if (mMap == null) {
              mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
          }
          if (mMap != null) {
              setUpMap();
          }
      }
  
      private void setUpMap() {
          mMap.addMarker(new MarkerOptions().position(new LatLng(36.0764, -94.1608)).title("Mark"));
      }
  
      @Override
      public void onMapReady(GoogleMap googleMap) {
          mMap = googleMap;
          // Add a marker in Sydney and move the camera
          LatLng sydney = new LatLng(-34, 151);
          mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
          mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
      }
  }
  </code></pre>