简体   繁体   English

如何添加仅使用GPS_PROVIDER作为提供者而不使用NETWORK_PROVIDER触发的位置接近警报

[英]How to add a location proximity alert that triggers only using GPS_PROVIDER as provider and not using NETWORK_PROVIDER

I am able to set a location proximity alert with addProximityAlert and receive the alerts with a broadcast receiver. 我可以使用addProximityAlert设置位置接近警报,并通过广播接收器接收警报。

But how will I be able to identify the location proximity alert is fired from a location provided by a GPS_PROVIDER and not a NETWORK_PROVIDER. 但是如何从GPS_PROVIDER而不是NETWORK_PROVIDER提供的位置触发位置接近警报。 I just want to make sure that the alerts are fired from an accurate location. 我只想确保从正确的位置发出警报。

I have exactly the opposite problem - I would not want it to use the GPS provider due to the battery drain. 我有完全相反的问题-由于电池电量耗尽,我不希望它使用GPS提供程序。 But it seems there is no currently known solution. 但是似乎没有当前已知的解决方案。 One thing I might be investigating is setting the location radius higher - hoping that a radius of 1000m would automatically not use GPS for example. 我可能正在研究的一件事是将位置半径设置得更高-例如,希望半径1000m会自动不使用GPS。 In my current testing, it seems a radius of 250m will definitely trigger GPS location. 在我目前的测试中,半径250m似乎肯定会触发GPS定位。 At leas 至少

I read on various sources that ProximityAlerts use BOTH Network and GPS provider, so I think that it really depends on the specified radius. 我从各种来源读到ProximityAlerts同时使用网络和GPS提供程序,因此我认为这实际上取决于指定的半径。 In my test, if I have GPS enabled but set a 1000m radius, it fires the alert in a way that makes me think it's using the Network provider, because I'm sure I'm over the 1000 radius (thus the position detected by the device could only be approximated) 在我的测试中,如果我启用了GPS但设置了1000m半径,它会以某种方式触发警报,使我认为它正在使用网络提供商,因为我确定自己超过了1000半径(因此,该设备只能近似)

It is not recommended to use GPS provider as it ideals when phone's screen is off, and battery drain issues, but still if you want to then use following: 不建议使用GPS提供程序,因为它最适合在手机屏幕关闭以及电池电量耗尽的情况下使用,但是如果您要使用以下内容,则仍然可以使用:

LocationListener ll;
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
locationManager.addProximityAlert(latitude, longitude, radius, -1, proximityIntent);
//you have to define latitude,longitude,radius etc parameters yourself

you can change "GPS_PROVIDER" to "NETWORK_PROVIDER" in order to use network provided location 您可以将“ GPS_PROVIDER”更改为“ NETWORK_PROVIDER”,以便使用网络提供的位置

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

相关问题 无法使用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 来自Android中GPS_PROVIDER或NETWORK_PROVIDER的位置不一致 - Location from GPS_PROVIDER or NETWORK_PROVIDER in android is not consistent 使用GPS_PROVIDER和NETWORK_PROVIDER获取当前位置的问题 - Issue in getting Current Location with GPS_PROVIDER and NETWORK_PROVIDER 如何提示用户启用GPS_PROVIDER和/或NETWORK_PROVIDER? - How to prompt user to enable GPS_PROVIDER and/or NETWORK_PROVIDER? 如何从GPS_PROVIDER自动更改为NETWORK_PROVIDER - How to change automatically from GPS_PROVIDER to NETWORK_PROVIDER 如何检查Xamarin表单中的network_provider和gps_provider? - How to check for network_provider and gps_provider in Xamarin forms? GPS定位仅在NETWORK_PROVIDER上有效? - GPS location working only on NETWORK_PROVIDER? 如果位置管理器无法通过GPS_Provider获取位置,请切换到NETWORK_Provider - If Location Manager cannot fetch location with GPS_Provider, switch to NETWORK_Provider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM