0
我需要在android中查找用戶位置。由於我不想使用GPS,我嘗試了下面的代碼來根據他/她的網絡查找用戶位置,這在一些設備上可用,但不是所有設備都可以使用,問題是什麼?是Android版本的問題還是硬件問題?Android位置監聽器在某些設備上不起作用
private double x, y;
private LocationManager lm;
lm = (LocationManager) getActivity().getSystemService(
Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,
0, locationListenerNetwork);
LocationListener locationListenerNetwork = new LocationListener() {
public void onLocationChanged(Location location) {
x = location.getLatitude();
y = location.getLongitude();
lm.removeUpdates(this);
Geocoder gcd = new Geocoder(getActivity(), Locale.getDefault());
List<Address> addresses;
addresses = gcd.getFromLocation(x, y, 1);
city = addresses.get(0).getLocality();
}