15,799,017 members
See more:
I'm developing a android application where user can save his required locations using latitude and longitude. A alarm should ring when user is near to that location.

Have developed the code for retrieving current location and even getting required location through geocoding. And Saved the longitude,latitude, title and description of location in a database.

Now not getting how to code , to ring a alarm and display related information when saved location matches with current location while comparing.

Plzz help.

Posted
Manfred Rudolf Bihy 16-May-12 6:37am
I added the javascript code from the website I pointed you to and added some comments that will help you translate the code to any other language. I hope you're at least comfortable with trigonometric functions like sine and cosine etc..

I hope you can work it out now!
Member 8727262 17-May-12 23:59pm
Thank you..

## Solution 1

All you have to do is define a proximity radius for each of the locations you stored in your data set. And then do a calculation of the distance between the current coordinates (latitude,longitude)current and the store coordinates (latitude,longitude)stored to find out the actual distance. If the actual distance is smaller or equal to the proximity radius you'll have to sound the alarm.

If you are unsure how to calculate the distance between two pairs of coordinates, see here: Calculate distance, bearing and more between Latitude/Longitude points[^].

JavaScript
```var R = 6371; // earth's radius in kilometers (km)

var dLat = (lat2-lat1).toRad(); // Conversion to radians can also be achieved by lat1 * Math.PI / 180
var dLon = (lon2-lon1).toRad(); // Conversion to radians can also be achieved by lat1 * Math.PI / 180

var lat1 = lat1.toRad(); // Conversion to radians can also be achieved by lat1 * Math.PI / 180
var lat2 = lat2.toRad(); // Conversion to radians can also be achieved by lat2 * Math.PI / 180

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // This now holds the distance expressed in km```

[/Edit]

Any questions left?

Regards,

Manfred

v2
Manfred Rudolf Bihy 15-May-12 17:15pm
You will not get any further help from me anymore if you are not willing to cooperate. You revoked your acceptance of my valid solution. I pointed you to a site that showed you how to calculate the distance. You absolutely failed to show if you even tried what I suggested to you. What did you expect? Did you think I'd provide a ready to use solution to you?
I'm very disappointed in your cooperative efforts.