Skip to content Skip to sidebar Skip to footer

How To Call Event Depening Upon Latitide And Longitude?

i am developing a location base application. which determines the latitude and longitude. now i want to compare it with same values and if matched i want to call event. i try it i

Solution 1:

Use the onLocationChanged()-method that is already in your code. If the user moves, you can do your coordinate-comparison and then fire your event.

http://developer.android.com/reference/android/location/LocationListener.html

Update: This is the code that you could use to detect whether you reached a certain destination:

Make two variables for latitute and longitude in your class. So for example:

double lat=10.0;
double lon=5.0;

Then modify the onLocationChanged()-Method to something like this:

@OverridepublicvoidonLocationChanged(Location location) {
 double currentLat=location.getLatitude();
 double currentLon=location.getLongitude();
 //you will need to create or reuse a distance-function... this should be easily findable...if (distance(lat,lon,currentLat,currentLon)<2.0){
 //do what you want to do...
 }
}

So for every location change that the phone detects, it will compare the distance to the last distance and fire the event...

Post a Comment for "How To Call Event Depening Upon Latitide And Longitude?"