In my application i want to get the updated location of the mobile user and i want to send it to the server continuously after periodic interval of certain time or after the user travels certain(say 500 meter) distance.I need these things to be done in backgroung.I know for this i have to implement service class. But I am not getting exactly how to do this.I did some work on that. Can anybody please help me in this issue. I did following things in the service class.
public class BackGroundService extends Service implements LocationListener{
public static final String Tag = BackGroundService.class.getName();
LocationManager myLocationManager;
Location myLocation;
LocationListener myLocationListener;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void OnCreate()
{
super.onCreate();
Log.d(Tag, "Service Started");
android.os.Debug.waitForDebugger();
Criteria criteria = new Criteria();
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAccuracy(Criteria.ACCURACY_LOW);
String locationProvider = myLocationManager.getBestProvider(criteria, true);
myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000*60*5, 500, myLocationListener);
myLocation = myLocationManager.getLastKnownLocation(locationProvider);
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
longitude = location.getLongitude();
latitude = location.getLatitude();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Log.d(Tag, "Provider is disabled");
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Log.d(Tag, "Location Provider is enabled");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
从这里,我想知道我怎样才能得到 目前的 Lat/ long 用户并把它发送到服务器上。