title: Android Marshmallow getLastLocation / LocationListeners not working
body: <p>I have an app which gets the users current location and then loads a Google Map and plots markers of interest in their area.  It works flawlessly on everything below Marshmallow.  I've added the run-time permissions check, and they are being set as I do get the prompt, and after I hit accept I see the Permission listed in the app details from the settings of the phone.  However, I can not for the life of me figure out why I'm getting no location back.  </p>
  
  <p>I am using the example as seen here <a href="https://developer.android.com/training/location/retrieve-current.html" rel="nofollow">https://developer.android.com/training/location/retrieve-current.html</a></p>
  
  <p>I have all the permissions set with the  tag in the manifest.  I even have my Fragment implementing the LocationListener.  However, the onLocationChanged method never gets called.  I am calling it within the onConnected method of the Google API Client like below..</p>
  
  <pre><code>@Override
      public void onConnected(@Nullable Bundle bundle) {
          try {
              Log.d("MYAPPTAG","isConnected: " + mGoogleApiClient.isConnected());
              LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
              myLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
          } catch (SecurityException ex) {
              myLocation = null;
          }
      }
  </code></pre>
  
  <p>the onConnected method DOES get called because I get my Log to the console.  myLocation is always null though.  I get a message in the console everytime I call getLastLocation that says </p>
  
  <pre><code>No Location to return for getLastLocation()
  GoogleSignatureVerifier: com.myappname.android signature not valid.  Found: LONG KEY HERE
  </code></pre>
  
  <p>Is there something special I need to do in Marshmallow?  </p>
  
  <p><strong>my OnLocationChanged method</strong></p>
  
  <pre><code>@Override
      public void onLocationChanged(Location location) {
          myLocation = location;
          Log.d("MYAPPTAG", "LocatinChngListner, loc: " + location.getLatitude() + "," + location.getLongitude());     
      }
  </code></pre>
  
  <p><strong>AndroidManifest.xml - permissions section (above  node)</strong></p>
  
  <pre><code>&lt;!--- App permissions --&gt;
      &lt;permission android:name="com.myappname.android.permission.MAPS_RECEIVE" android:protectionLevel="signature"/&gt;
      &lt;uses-permission android:name="com.myappname.android.permission.MAPS_RECEIVE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS"/&gt;
      &lt;uses-permission android:name="android.permission.CALL_PHONE"/&gt;
      &lt;uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
      &lt;permission android:name="com.myappname.android.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="com.myappname.android.permission.C2D_MESSAGE"/&gt;
  </code></pre>
  
  <p><strong>onCreate Method snippet</strong></p>
  
  <pre><code>createLocationRequest();
          if (mGoogleApiClient == null) {
              mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .addApi(LocationServices.API)
                  .build();
          }
  </code></pre>
  
  <p><strong>createLocationRequest method</strong></p>
  
  <pre><code>private void createLocationRequest(){
          mLocationRequest = LocationRequest.create();
          mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
          mLocationRequest.setInterval(5000);
          mLocationRequest.setFastestInterval(1000);
      }
  </code></pre>
  
  <p><strong>onStart() onStop() methods</strong></p>
  
  <pre><code>@Override
  public void onStart() {
          if (!mGoogleApiClient.isConnected()) mGoogleApiClient.connect();
          super.onStart();
      }
  
  @Override    
  public void onStop() {
          if (mGoogleApiClient.isConnected()) mGoogleApiClient.disconnect();
          super.onStop();
      }
  </code></pre>
  
  <p>I call this code below right after the Fragment onCreate method</p>
  
  <pre><code>if (Build.VERSION.SDK_INT &gt; Build.VERSION_CODES.LOLLIPOP_MR1 &amp;&amp; (ContextCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
              requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }, REQUEST_PERMISSION_USER_LOCATION);
          } else {
              googleMapsLocationPermissionContainer.setVisibility(View.GONE);
              getUserLocationAndInitializeMap();
          }
  </code></pre>
  
  <p>googleMapsLocationPermissionContainer is just a layout I overlay on the map until the permissions are granted.  </p>
  
  <p><strong>getUserLocationAndInitializeMap()</strong></p>
  
  <pre><code>try {
                  MapsInitializer.initialize(getActivity());
                  // Set reference for map object
                  if (map == null) {
                      mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
                      mapFragment.getMapAsync(this);
  // Here I set the map to invisible then after I plot all the markers I set it to visible again
  
                      mapFragment.getView().setVisibility(View.INVISIBLE);
                  }
              } catch (Exception e) {
                  // Show the google maps alert dialog
                  showGoogleMapsErrorDialog();
              }
  </code></pre>