Search code examples
javascriptgeolocationmobile-browser

How should I calculate if a person is within 50 meters range of a store using geolocation?


I have the store's latitude and longitude saved in database, and the user's geolocation is obtained with javascript from his mobile browser.

How should I calculate if the user's distance from the store is within 50m?

Maybe (x1-x2)**2+(y1-y2)**2 < a certain threshold ?

p.s. This is like foursquare checkin.


Solution

  • This site (Calculate distance, bearing and more between Latitude/Longitude points) provide a good explanation and calculation formula. You may want to check it out.