我正在使用 Location 开发 android 应用程序。我可以使用以下代码获取当前位置。
public void GetLocation()
{
boolean isGPSEnabled = false;
boolean isNetworkEnabled = false;
private LocationManager mLocationManager;
private String mProvider;
mLocationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
isGPSEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(isGPSEnabled && isNetworkEnabled)
{
mProvider = mLocationManager.getBestProvider(criteria, false);
Location location = mLocationManager.getLastKnownLocation(mProvider);
Sring mLatitude=String.valueOf(arg.getLatitude());
String mLongitude=String.valueOf(arg.getLongitude());
}
}
一旦位置不经常更改,我需要在后台更新用户的位置。我怎样才能做到这一点?