我正在尝试根据网络提供商获取用户位置,但该事件从未发生,并且该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);
}
可能是什么问题呢?我在这里做错了吗?