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();
}