Reputation: 1
i was unable to switch provider from GPS to Network in background service.With help Gps provider i get updated location periodically using background service but when GPS is off then how get latitude & longitude of updated location?
Upvotes: 0
Views: 315
Reputation: 4157
You should use LocationManager in Service
LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
Log.i("location...","...latt"+location.getLatitude()+"longg..."+location.getLongitude());
String my_latitude = String.valueOf(location.getLatitude());
String my_longitude = String.valueOf(location.getLongitude());
}
Upvotes: 3