我正在开发一个使用位置的应用程序。
我的问题:
当我寻找最好的提供商时,我只得到“网络”。
我知道为什么,但我不知道如何改进。
在位置设置中,当我检查“参数 -> 位置”和“安全设置 -> 使用无线网络”时,LocationManager.getBestProvider()
仅返回网络。当未选中且 GPS 处于 Activity 状态时,getBestProvider
返回 GPS。
我想做的是:
选中这两个选项后,如何使用/检测 GPS(而不是网络)作为位置提供程序。
最佳答案
您必须首先检查 GPS 是否打开。如果打开则从 GPS 获取位置,如果未打开则从网络获取位置。
要检查 GPS 状态,请使用:
manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
关于android - locationManager.getBestProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9498409/