We are developing a live-stream, browser based racing game. Our
contenders will start to race from a START point and first contender
who check-in in STOP venue will won race.
For example this venue will be our STOP venue : https://foursquare.com/venue/2154697
But there is a problem. For example now i’m 1.3km far away from STOP
venue but i can check-in and i can win race 🙂 So i have to calculate
distance and if distance is lower than 100meters, contender will win.
How can we do it ?
In shortly, i have to verify, contender is really in this venue.
I would suggest that you not use the check in feature to determine a win for exactly the reasons you mention above. Rather, I would suggest that you pull the winning location from foursquare, and then use a native lookup of the device’s lat/long to compare to.
If you are making a browser based game, you can pull GPS info directly in JS in most modern OS’s browsers (iOs, Android, Palm, etc). Almost all app frameworks support this now as well. While GPS lookup in the browser is a legitimate spec, there are handy JS warpers that help with cross compatibility like this one [[ http://code.google.com/p/geo-location-javascript/ ]]
So now that you know the ‘destination’ lat/lon and the true position of the player, you can calculate the delta from the location with some trigonometry. Remember though that the lat and log deltas themselves are not as simple as subtraction, as you are playing on a curved surface. The good news is that this stackOverflow article covers how to do this [[ Calculate distance between 2 GPS coordinates ]]