如何获取用户的当前位置?

如何获取用户的当前位置?

问题描述:

我想根据 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

你用的是百度的api么?
有申请申请密钥(key)么
我的资源里有一个demo,你可以拿去看看,不要下载分数