I made a android application with multiple Geolocation on Google map (pins) I would like to send a notification when the user is close to one of these locations. Any ideas?
Asked
Active
Viewed 825 times
1 Answers
3
This is actually fairly easy. First, set up an application that monitors your location. This post will show you more on that.
Once you know your position, you can simply determine if you're within a certain range of it. To calculate the distance between two points, try the Location
class:
Location.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, results);
results
is a float[]
, so to return the distance, simply use float distance = results[0];
.
So, in a nutshell, compile a list of waypoints you want to recognize. Then, in your GPS monitoring code, regularly check the distance between yourself and the list of points. If you're within a threshold, say 100m, then send a notification as a Toast
message or something.
Good luck!