title: Location Updates only when the app is opened for the second time
body: <p>In android studio, while using a GoogleApiClient, after the user grants permissions, when the app is first launched, I do not get any location updates,but when I open the app again,I start receiving the updates. This started happening happening after I modified my code to add setMyLocationEnabled().
  My code is given below.
  I have only added the main Activity where I have two text boxes and a map fragment.</p>
  
  <pre><code>package b.tipsy.checkforlocation;
  import android.Manifest;
  import android.app.FragmentManager;
  import android.app.FragmentTransaction;
  import android.content.pm.PackageManager;
  import android.location.Address;
  import android.location.Geocoder;
  import android.location.Location;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.v4.app.ActivityCompat;
  import android.support.v4.content.ContextCompat;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.google.android.gms.common.ConnectionResult;
  import com.google.android.gms.common.api.GoogleApiClient;
  import com.google.android.gms.location.LocationListener;
  import com.google.android.gms.location.LocationRequest;
  import com.google.android.gms.location.LocationServices;
  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;
  
  import java.io.IOException;
  import java.util.List;
  import java.util.Locale;
  
  public class MainActivity extends AppCompatActivity implements 
  GoogleApiClient.ConnectionCallbacks, 
  GoogleApiClient.OnConnectionFailedListener, LocationListener, 
  OnMapReadyCallback {
  private GoogleApiClient mGoogleApiClient;
  TextView latitute;
  TextView longitute;
  private LocationRequest mLocationRequest;
  private Double myLatitute;
  private Double myLongitute;
  Location current_location;
  GoogleMap mMap;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      SupportMapFragment mapFragment = (SupportMapFragment) 
      getSupportFragmentManager()
              .findFragmentById(R.id.map);
      mapFragment.getMapAsync((OnMapReadyCallback) this);
      latitute = (TextView) findViewById(R.id.lat);
      longitute = (TextView) findViewById(R.id.lon);
  
  
  
  }
  
  @Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      switch (requestCode) {
          case 0x1:
              if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  Toast.makeText(this, "Permission is granted", Toast.LENGTH_SHORT).show();
                  if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
                      mMap.setMyLocationEnabled(true);
              }
  
      }
  
  
  }
  
  public synchronized void buildGoogleApiClient() {
      mGoogleApiClient = new GoogleApiClient.Builder(this)
              .addApi(LocationServices.API)
              .addConnectionCallbacks(this)
              .addOnConnectionFailedListener(this)
              .build();
      mGoogleApiClient.connect();
  
  }
  
  @Override
  public void onConnected(@Nullable Bundle bundle) {
      Log.d("Just", "Connection established. Fetching location ..");
      if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
              == PackageManager.PERMISSION_GRANTED) {
          mMap.setMyLocationEnabled(true);
          mLocationRequest = LocationRequest.create();
          mLocationRequest.setInterval(5000);
          mLocationRequest.setFastestInterval(5000);
          mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
          LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
      }
  }
  
  @Override
  public void onConnectionSuspended(int i) {
  }
  
  @Override
  public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
      Log.e("The error was", "The error was" + connectionResult.toString());
  }
  
  @Override
  public void onLocationChanged(Location location) {
      Log.d("Just", "works!");
      latitute.setText(String.valueOf(location.getLatitude()));
      longitute.setText(String.valueOf(location.getLongitude()));
      LatLng latLng=new LatLng(location.getLatitude(),location.getLongitude());
      mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
      mMap.addMarker(new MarkerOptions().position(latLng));
      mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
  
  }
  
  @Override
  protected void onStart() {
      super.onStart();
  
  }
  
  @Override
  protected void onStop() {
      super.onStop();
  }
  
  @Override
  protected void onResume() {
      super.onResume();
  }
  
  @Override
  protected void onPause() {
      super.onPause();
  }
  
  @Override
  public void onMapReady(GoogleMap googleMap) {
      mMap = googleMap;
      buildGoogleApiClient();
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
          ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0x1);
      }
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED ) {
        Log.d("Just","In Map Ready");
          mMap.setMyLocationEnabled(true);
  
      }
  
  
  
  }
  }
  </code></pre>