我有一台没有gps的平板电脑只有wi-fi,我想通过Wi-Fi获取设备位置,但网络提供商给我总是空的。 我究竟做错了什么?我还有其他选择吗?
LocationManager locationManager = (LocationManager) ResourceManager.getActivity().getSystemService(MainActivity.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
};
if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)){
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
//if (locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)!=null)Log.d("xxxx", "xxxx");
}
});
答案 0 :(得分:0)
我可以提出两种方法。