# Checking distance between lat/long pairs

I am currently developing an app that makes you run a certain distance in 30 seconds. I have code to gather the starting longitude and latitude, but I got stuck with comparing them with the current latitude and longitude. Is there any way to check if the distance they travelled is at least a certain number? I would like to have them travel a certain radius so no matter which direction they run in, and as long as they have ran the target distance, they will complete the game. Any ideas?

You need to calculate the distance. Most people use the Haversine formula for that. Itâ€™s a pain to set up but it works great.

See this: Calculate distance travelled

Note that that will calculate the distance between two points â€śas the crow flies.â€ť If you want actual road distance, youâ€™d probably need to use an API call with the Google Maps API.

Thanks! The only problem is I donâ€™t really know how to make it apply to what Iâ€™m doing. My idea is once a player hits a button to start, then everything activates. Any way you could help me?

What kind of help do you need?

I recommend first writing an algorithm that contains the main steps youâ€™re going to need. So when you say â€śthen everything activatesâ€ť, that should be broken down into maybe 4-5 separate steps. That way you can ask questions about specific steps that youâ€™re having trouble with. You started to do that in your first post so itâ€™s just getting a little more specific and putting things in a specific order (e.g. numbered steps).

I have it so when the â€śgame startsâ€ť screen opens, it gathers the current latitude and longitude and stores them in their own variables. I then have a function called â€ścheck locationâ€ť where the comparing will happen.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.