mum
mum

Reputation: 1645

How call requestLocationUpdates in thread?

I want get my location from a thread. I code as:

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

But How call requestLocationUpdates update location? Can you help me?

Upvotes: 0

Views: 1335

Answers (1)

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28541

You have everything on the developer documentation: 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);

Upvotes: 1

Related Questions