0

Possible Duplicate:
What is the simplest and most robust way to get the user’s current location in Android?

I have studies the location api for android and tried the basic apps which have the use of the locationChanged method and provide a simplest solution to keep track of use location.

How can keep track of the following actions of user in the same context

  • user entering a new location
  • user leaving the current location

and also about the following factors :

  • the new location is not within say x meters of the old location
  • and the attributes required for comparing the last and new location
Community
  • 1
  • 1
Himanshu Soni
  • 264
  • 8
  • 15

1 Answers1

0

This isn't bad. The official Android SDK on this matter is actually pretty good. Official Google Documentation on it

Basically the interface it uses runs functions as each one of these situations arises. So, onLocationChanged gets called whenever the location changes according to whatever parameter fires that off. Also, I would recommend just playing with the different provider types

The hardest part is the distance part. There's equations out there to calculate distance using longitude and latitudes.

From the documentation:

// 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);
Joe Plante
  • 6,308
  • 2
  • 30
  • 23