【发布时间】:2019-05-22 20:29:12
【问题描述】:
我正在尝试实现一个功能来监控在特定位置花费的时间。
我已经实现了“requestLocationUpdates”函数,以使用 Google Maps API 接收有关当前用户位置的更新。
public Location get_location(){
if( is_walking ){
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
Toast.makeText(context,"Permission not granted",Toast.LENGTH_SHORT).show();
return null;
}
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
boolean is_gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (is_gps_enabled){
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,15000,5,this);
Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
return l;
}else {
}
return null;
}else
return null;
我是否只是继续保存数组中的更新时间并将它们相互比较?那不是很消耗内存吗?
【问题讨论】: