【发布时间】:2019-10-11 00:34:52
【问题描述】:
我无法使用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?) {
}
}
【问题讨论】:
-
你可以参考这个仓库:github.com/yash786agg/GPS
-
到外面去。 GPS 在室内无法工作。
-
你在manifest中添加精细位置权限了吗?
-
是的,我在清单文件中添加了很好的位置。
-
如果针对现代 Android 版本,添加到清单是不够的。需要“精确位置”的运行时权限。
标签: android kotlin android-gps