I have a working app that posts a toast when the user is in a predefined distance from a point on the map.
To recieve my distance from the user location and the point I've used
final float result[] = new float[2];
Location.distanceBetween(prevJoblatlng.latitude, prevJoblatlng.longitude, myLocationMarker.getPosition().latitude, myLocationMarker.getPosition().longitude, result);
And in the onLocationChanged
function I've used a handler to post every ten seconds.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (result[0] <= circle.getRadius()) {
Toast.makeText(MainActivity.this, "You're nearby a task.", Toast.LENGTH_SHORT).show();
}
}
}, 10000);
However this is working somehow but when the user is out of the are the Handler is still in queue and sends toasts. How do I stop the Handler once I am beyond the distance?