如果我的监听器监听网络和GPS卫星如何删除只有网络供应商? [英] How do I remove only the network provider if my listener listens for both network and satellite gps?

查看:130
本文介绍了如果我的监听器监听网络和GPS卫星如何删除只有网络供应商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的情景。我需要获得GPS卫星从优先考虑。然而,如果室内,会有没有接收到新的位置。我所做的是,如果有2分钟后没有接收到新的位置,那么我将切换到网络GPS。但是,如果用户什么走到外面,应用程序也不会知道,因为它已经从网络GPS听,也不会收到来自卫星的位置了。

Here's the scenario. I need to prioritize getting GPS from satellite. However if indoor, there will be no new locations received. What I did was if there's no new location received after 2 minutes, then I will switch to network GPS. However, what if the user went outside, the app wouldn't know because it's already listening from network GPS, it will not receive locations from satellite anymore.

所以它会更好,如果我可以听新的位置更新,天气从卫星或网络。虽然更好,如果我可以从卫星的那些优先级。

so it would be better if I could listen to new location updates, weather be from satellite or from network. though better if I can prioritize the ones from satellite.

我发现这个问题,所选择的答案真的帮了大忙:<一href=\"http://stackoverflow.com/questions/13509452/android-locationlistener-switching-from-gps-to-network\">Android LocationListener的全球定位系统切换到网络

I found this question and the chosen answer really helped a lot: Android LocationListener Switching from GPS to Network

但是,有只是让我感到困惑的一部分。他说:
您在安装相同LocationListener的两个供应商。为了从您收到的位置indentify你需要测试它是这样的:

But there was just a part that confused me. He said: You setup the same LocationListener for both providers. To indentify from where you are receiving the location you need to test it like this:

public void onLocationChanged(Location fix) {
    if(fix.getProvider().equals(LocationManager.GPS_PROVIDER)){
        //here Gps
    } else if(fix.getProvider().equals(LocationManager.NETWORK_PROVIDER)){
        //here Network
    }
}

所以,如果是那样的话,我该如何禁用只从网络运营商接收更新?因为如果我用一个单一的监听器,监听GPS和网络,然后当我做 removeUpdates(thatListener),那么该侦听器将不会收到任何(卫星或网络)GPS更新了。

so if that's the case, how do I disable receiving updates from only the network provider? because if I use a single listener which listens to both gps and network, then when I do removeUpdates(thatListener), then that listener will not receive any (satellite or network) gps updates anymore.

但如果他说,我会让听众2这是刚才一模一样(除了一个是卫星一个是网络),那么我就不需要检查哪个供应商给了位置,因为每个听众将有自己的 onLocationChanged 方法。我是否错过了什么?我没有足够的声誉,所以我不能直接评论他的答案

but if he's saying that I'll make 2 listeners which are just exactly the same (except one is for satellite one is for network), then I wouldn't need to check which provider gave the location because each listener will have its own onLocationChanged method. Am I missing out on something? I don't have enough reputation so I can't comment directly to his answer

此外,多久GPS卫星通常能够接收位置更新之前走?

also, how long does satellite GPS usually take before being able to receive location updates?

非常感谢你! :)

推荐答案

我想新的融合位置提供由满足您的需求。让谷歌为你做这项工作,并始终以最佳的供应商present。你需要谷歌播放安装该服务,但多数民众赞成大多是没有问题的。安装程序Locationservice,已经成为这一容易得多。请参见这里一个很好的例子。

I guess the new Fused location provider is made to suit your needs. Let Google do this work for you and always take the best Provider present. You'll need Google Play Service installed for that, but thats mostly no problem. Setup the Locationservice has become much easier with this. See here for a nice example.

这篇关于如果我的监听器监听网络和GPS卫星如何删除只有网络供应商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆