[英]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.