简体   繁体   English

Android:locationManager GPS_provider VS Network_provider

[英]Android: locationManager GPS_provider VS Network_provider

I have these two lines of code ready to be used in the section of my app where the user's location is requested: 我准备在需要用户位置的应用程序部分中使用以下两行代码:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, locationListener);

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, locationListener);

The problem is that, when testing in real device, I have noticed that, using GPS_provider does not work very well when being in certain places like inside of a building....the app is stuck waiting to acquire GPS coordinates which take a lot of time or just never come unless I have open-sky conditions. 问题是 ,在真实设备中进行测试时,我注意到,在建筑物内的某些地方使用GPS_provider不能很好地工作。...应用程序被困在等待获取大量GPS坐标的过程中时间,或者除非我有露天条件,否则永远不会来。

The question would be : how do I do to still use GPS_provider by default but, if gps coordinates take more than XXXX seconds to be acquired, then switch to Network_provider and acquire position from Network. 问题将是 :如何在默认情况下仍使用GPS_provider ,但如果要获取GPS坐标花费XXXX秒以上的时间,请切换到Network_provider并从Network获取位置。

Small edit: is it maybe any way to check GPS signal strength before using GPS or Network provider? 小修改:在使用GPS或网络提供商之前,可以用任何方法检查GPS信号强度吗?

LocationListener has a function onStatusChanged() . LocationListener具有onStatusChanged()函数。 You have to override this function to check GPS_PROVIDER's status and accordingly take necessary action , which in your case is switching to NETWORK_PROVIDER. 您必须重写此功能才能检查GPS_PROVIDER的状态,并采取相应的措施,在您的情况下,该方法将切换到NETWORK_PROVIDER。

Hope this answers your query 希望这能回答您的查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android LocationManager从NETWORK_PROVIDER或GPS_PROVIDER获取经度和纬度是否更加耗费资源? - Android LocationManager is it more resource intensive to get the longitude and latitude from NETWORK_PROVIDER or GPS_PROVIDER? 来自Android中GPS_PROVIDER或NETWORK_PROVIDER的位置不一致 - Location from GPS_PROVIDER or NETWORK_PROVIDER in android is not consistent 在android中,GPS_PROVIDER有效,但NETWORK_PROVIDER不起作用 - in android, GPS_PROVIDER works, but NETWORK_PROVIDER does not 如何提示用户启用GPS_PROVIDER和/或NETWORK_PROVIDER? - How to prompt user to enable GPS_PROVIDER and/or NETWORK_PROVIDER? 无法使用GPS_PROVIDER / NETWORK_PROVIDER获取用户位置 - Not getting user location using GPS_PROVIDER / NETWORK_PROVIDER 使用OnStatusChanged从GPS_PROVIDER切换到NETWORK_PROVIDER? - Using OnStatusChanged to switch to NETWORK_PROVIDER from GPS_PROVIDER? getLastKnownLocation使用GPS_PROVIDER和NETWORK_PROVIDER返回NULL - getLastKnownLocation return NULL using GPS_PROVIDER and NETWORK_PROVIDER NETWORK_PROVIDER和GPS_PROVIDER在片段中返回null - NETWORK_PROVIDER and GPS_PROVIDER returns null in fragments 使用GPS_PROVIDER和NETWORK_PROVIDER获取当前位置的问题 - Issue in getting Current Location with GPS_PROVIDER and NETWORK_PROVIDER 如何从GPS_PROVIDER自动更改为NETWORK_PROVIDER - How to change automatically from GPS_PROVIDER to NETWORK_PROVIDER
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM