如何在线程中调用requestLocationUpdates?

时间:2012-10-16 11:09:03

标签: android

我想从一个帖子中获取我的位置。 我编码为:

LocationManager locationManager;
            GeoPoint p;
            locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            Criteria cri = new Criteria();
            String tower = locationManager.getBestProvider(cri, false);
            Location location = locationManager.getLastKnownLocation(tower);    

但是如何调用requestLocationUpdates更新位置? 你能救我吗?

1 个答案:

答案 0 :(得分:1)

您拥有开发人员文档中的所有内容:Requesting Location Updates

// 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.
      makeUseOfNewLocation(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);