无法通过 LocationManager.GPS_PROVIDER 获取 GPS 坐标

Cannot Fetch GPS Coordinates Through LocationManager.GPS_PROVIDER

我无法使用 LocationManager.GPS_PROVIDER 获取位置。但它正在与 LocationManager.NETWORK_PROVIDER.

一起工作
val locationManager=getSystemService(Context.LOCATION_SERVICE) as LocationManager

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,500, 100F,listener)//It's working if i use NETWORK_PROVIDER

val listener=object :LocationListener {
    override fun onLocationChanged(location: Location?) {
        latitude = location!!.latitude.toString()
        longitude = location!!.longitude.toString()

        Log.d("location", "$latitude $longitude")
    }

    override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
    }

    override fun onProviderEnabled(provider: String?) {
    }

    override fun onProviderDisabled(provider: String?) {
    }
}

两种解决方案:
1. 可能您的移动设备关闭了 GPS 定位。所以尝试打开它并检查位置。
2. 尝试实施由 Google Play 服务 API 提供的 Fused location provider,因为它可以提高性能、节省电池寿命并提供更准确的位置