GPS 和网络的标准
我想知道如何从最佳提供商处获取位置
我是否必须制定两个单独的标准 1 用于 GPS,1 用于网络,还是有办法将它们全部放在一起?
这是我的代码,当我添加粗略标准时,GPS 无法运行(屏幕顶部没有 GPS 闪烁徽标),而当我使用精细标准时,我没有从网络获得任何东西......那么我是否必须为两者编写标准并在可用的条件之间进行切换,或者它们是否可以采用相同的标准?
因为我有“getBestProvider(criteria, true);”在我的代码中,所以它应该从最好的提供商处获取位置......对......??!
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//// criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
String provider = locationManager.getBestProvider(criteria, true);
I would like to know how can I get location from the best provider
do I have to make two separate criteria 1 for the GPS and 1 for the network or is there a way to put them all together ?
this is my code when I add the COARSE criteria the GPS does not go on (no GPS flashing logo on the top of the screen) and when I use the FINE criteria I dont get any thing from the network.......so do I have to write criteria for both and switch between them for what ever is available or can they both be in the same criteria ?
because I have the "getBestProvider(criteria, true);" in my code so it should get the location from the best provider....right..??!
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//// criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
String provider = locationManager.getBestProvider(criteria, true);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
getBestProvider
与Criteria.ACCURACY_FINE
一起使用将永远不会返回NETWORK_PROVIDER
,即使 wifi 位置通常非常准确。在我的应用程序中,我使用
getProviders
获取所有 符合我的条件的提供商,然后添加NETWORK_PROVIDER
(如果它已激活但尚未出现在列表中) 。然后,我为每个提供程序启动
requestLocationUpdates
,确保在获得足够准确的位置时调用removeUpdates
。这样,如果网络提供的位置足够准确,GPS 提供商将被关闭
Using a
getBestProvider
withCriteria.ACCURACY_FINE
will never return theNETWORK_PROVIDER
, even though wifi position is usually quite accurate.In my application, I use
getProviders
to get all providers matching my criteria, then add theNETWORK_PROVIDER
if it is activated and not yet in the list.Then I launch a
requestLocationUpdates
for each of these providers, making sure to callremoveUpdates
when I get a location accurate enough.This way, if the location provided by the network is accurate enough, the gps provider will be turned off
如果未启用 gps,带有 Criteria.ACCURACY_FINE 的 @nicopico getBestProvider 可以返回 NETWORK_PROVIDER
我在我的应用程序中使用以下代码
此代码位于实现 locationListener 的类中
您可以编辑此行
以反映您的 locationListener 实现
@nicopico getBestProvider with Criteria.ACCURACY_FINE can return the NETWORK_PROVIDER if gps is not enabled
i use the following code in my app
this code is in a class that implements locationListener
you can edit this line
to reflect your implementation of locationListener