【发布时间】:2017-09-10 08:57:05
【问题描述】:
我正在开发一个在启动时获取用户位置的应用程序。我正在使用Smart Location Library 来获取位置和反向地理编码。但主要问题是即使在应用程序关闭后,GPS 也会在通知中显示。我检查了堆栈跟踪,但没有发现任何泄漏的窗口异常。 我正在使用此代码来获取我的位置..
private void getMyLocation(){
final long mLocTrackingInterval = 1000000 * 5; // 5 sec
float trackingDistance = 1000 * 10;
LocationAccuracy trackingAccuracy = LocationAccuracy.HIGH;
LocationParams.Builder builder = new LocationParams.Builder()
.setAccuracy(trackingAccuracy)
.setDistance(trackingDistance)
.setInterval(mLocTrackingInterval);
SmartLocation.with(mContext)
.location(provider)
// .continuous()
.oneFix()
.config(builder.build())
.start(this);
}
@Override
public void onLocationUpdated(Location location) {
SmartLocation.with(mContext).geocoding()
.reverse(location,new OnReverseGeocodingListener() {
@Override
public void onAddressResolved(Location location, List<Address> results) {
if (results.size() > 0) {
mAddressList=results;
mLocation=location;
tvLocation.setText( results.get(0).getAddressLine(0)+"\n"+results.get(0).getAddressLine(1));
}
}
});
}
和 onStop() 主要活动的方法..
@Override
protected void onStop() {
super.onStop();
SmartLocation.with(mContext).location(provider).stop();
SmartLocation.with(mContext).geocoding().stop();
}
编辑
我正在使用这个 pvider。我也尝试过其他提供商。但结果还是一样。
private LocationGooglePlayServicesWithFallbackProvider provider=new LocationGooglePlayServicesWithFallbackProvider(mContext);
我尝试了很多,但无法弄清楚实际问题是什么。任何帮助,将不胜感激。谢谢
【问题讨论】:
-
你在用什么
provider? -
@azizbekian 我正在使用
LocationGooglePlayServicesWithFallbackProvider也尝试过其他提供商 -
使用 SmartLocation.with(context).location().stop();停止位置监听。
-
@VivekSinha 我已经在 Activty 的
onStop()方法上添加了这段代码。 -
你测试过 .stop() 方法吗?您可以通过手动调用 .stop() 方法来做到这一点,该方法由按钮触发,因此您知道这些调用有效。
标签: android android-location android-gps