1

I can't get my last known location to return and call addMarker. It is saying that the appropriate API was not requested in my error stack. it's a big program so I'm just putting the important parts here:

public LatLng getLastKnownLocation() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    }
    Location lastLocation = FusedLocationApi.getLastLocation(client);
    return new LatLng(lastLocation.getLatitude(),lastLocation.getLongitude());

}

Called from:

mMap.addMarker(newMarkerOptions().position(getLastKnownLocation()).title(memoryString));

And my error:

23126-23126/com.example.kevin.memories E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.kevin.memories, PID: 23126 java.lang.NullPointerException: Appropriate Api was not requested. at com.google.android.gms.common.internal.zzaa.zzb(Unknown Source) at com.google.android.gms.internal.zzof.zza(Unknown Source) at com.google.android.gms.location.LocationServices.zzi(Unknown Source) at com.google.android.gms.location.internal.zzd.getLastLocation(Unknown Source) at com.example.kevin.memories.MapsActivity.getLastKnownLocation(MapsActivity.java:134) at com.example.kevin.memories.MapsActivity.onMapReady(MapsActivity.java:107) at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source) at com.google.android.gms.maps.internal.zzo$zza.onTransact(Unknown Source) at android.os.Binder.transact(Binder.java:380) at wv.a(:com.google.android.gms.DynamiteModulesB:82) at maps.ag.t$5.run(Unknown Source) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5835) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 23126-23745/com.example.kevin.memories E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.googlecertificates.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.example.kevin.memories-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

Am I missing something?

@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    Toolbar toolbar = (Toolbar) findViewById(R.id.login_toolbar);
    toolbar.setTitle("Login");

    if (client == null) {
        GoogleApiClient client = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        loginButtons();
    }
    loadMap();
}
marcospereira
  • 12,045
  • 3
  • 46
  • 52
kevinb
  • 17
  • 9

1 Answers1

0

I'm getting the same log error here In my case GoogleApiClient is not returning null. I don't have a problem with getting a non null last location. I verified this with a toast. The only problem that I have is that the marker displaying code is never called. In case your client is still returning a null have a look at my implementaion. This is for getting the last location. The solution for the log error itself is downgrading 9.0.83 Google Play Services.

Community
  • 1
  • 1