microg / microg/GmsCore

How to use FusedLocationProviderClient for getting location?

Open
#2,090 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Java
Stars
14.6k
Forks
3.2k
Avg merge
12d 11h
Merged PRs (30d)
4

Description

Hi,
I have installed latest release GmsCore to my device (Android S without GMS), and already granted all necessary permissions.

I wrote two test functions in my test app:
Use LocationManager can work fine.

fun getLocation1() {
    if (ActivityCompat.checkSelfPermission(
            this,
            permission.ACCESS_FINE_LOCATION
        ) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(
            this,
            permission.ACCESS_COARSE_LOCATION
        ) != PackageManager.PERMISSION_GRANTED
    ) {
        return
    }
    var location = locationManager!!.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
    if (location != null) {
        Log.e(tag, "lat: ${location.latitude} lon: ${location.longitude}")
    }
}

But use FusedLocationProviderClient always throw exception:

fun getLocation2() {
    if (ActivityCompat.checkSelfPermission(this, permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return
    } else {
        val mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
        mFusedLocationClient.lastLocation.addOnCompleteListener {
            val location = try {
                it.result
            } catch (ex: Exception) {
                Log.e(tag, "Cannot get location result $ex")
                null
            }

            if (location != null)
              Log.e(tag, "lat: ${location.latitude} lon: ${location.longitude}")
        }
    }
}
com.example.locationtest requires the Google Play Store, but it is missing.
The service for com.google.android.gms.internal.location.zzda is not available: ConnectionResult{statusCode=SERVICE_INVALID, resolution=null, message=null}
Cannot get location result com.google.android.gms.tasks.RuntimeExecutionException: com.google.android.gms.common.api.ApiException: 17: API: LocationServices.API is not available on this device. Connection failed with: ConnectionResult{statusCode=SERVICE_INVALID, resolution=null, message=null}

I am using play-services-location 21.0.1
implementation 'com.google.android.gms:play-services-location:21.0.1'

Did I miss anything?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported call to LocationServices.getFusedLocationProviderClient and lastLocation with play-services-location 21.0.1 on Android S without GMS, using the exception output as the initial evidence. The issue does not name a GmsCore file or test; completion would require identifying the supported behavior or a concrete project change for this API failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.