我试图获取基于网络提供程序的用户位置,但是该事件从未发生,并且UpdateLocation()方法也从未被调用。
这是代码:

public void UpdateLocation(Location location)
{
    GeoPoint geoPoint = new GeoPoint((int)(location.getLatitude() * 1E6),(int)(location.getLongitude() * 1E6));
    MapController controller = mapView.getController();
    controller.setCenter(geoPoint);
}
public void GetLocation()
{
     // Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
          // Called when a new location is found by the network location provider.
          UpdateLocation(location);
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {}

        public void onProviderEnabled(String provider) {}

        public void onProviderDisabled(String provider) {}
      };

    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}


可能是什么问题呢?我在这里做错什么了吗?

最佳答案

如果我没记错的话,NETWORK_PROVIDER使用wifi信号找出位置。

要验证的几件事:


wifi开启了吗?
设备是否正在注册wifi信号?超过一个? (一个可能还不够)
在设置的“位置服务”下是否选中了“使用无线网络”?

10-04 22:57
查看更多