我想根據 Network Provider 獲取用戶的當前位置,但是沒有成功,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);
}
LocationManager.NETWORK_PROVIDER是不是沒得到啊,GPS_PROVIDER