我无法在后台服务中将提供商从GPS切换到网络。使用帮助Gps提供商我会定期使用后台服务获得更新位置,但是当GPS关闭时,如何获得纬度和经度更新的位置?
答案 0 :(得分:3)
您应该在服务
中使用 LocationManagerLocationManager 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());
}