-1

I have one database table in which I have Longitude,Latitude and DateTime of User, after every 2 seconds the record is inserted in database table with different latitude and longitude. My Task is to find out how many times users vehicle had stay for more than 15 mins in area of 100 or 200 meters.

LogId   UserId  Latitude    Longitude   CreatedDate
23  3   19.8861455500   75.3164193833   2017-05-11 20:49:09.000
24  3   19.8861096167   75.3163952833   2017-05-11 20:49:10.000
25  3   19.8860737833   75.3164109000   2017-05-11 20:49:12.000
26  3   19.8860663167   75.3164390667   2017-05-11 20:49:14.000
27  3   19.8860388000   75.3164496000   2017-05-11 20:49:16.000
28  3   19.8860183333   75.3164691833   2017-05-11 20:49:19.000
29  3   19.8859985667   75.3164865000   2017-05-11 20:49:20.000
30  3   19.8859775667   75.3165013333   2017-05-11 20:49:22.000
31  3   19.8859546167   75.3165024667   2017-05-11 20:49:24.000
32  3   19.8859062000   75.3164335000   2017-05-11 20:49:25.000

Like if driver of vehicle is stop for lunch/for any personal work and spend his most time in particular small areas of city. I have to calculate his stay times in particular time frame.

I did't find any logic to solve this problem. If you got any solution its highly appreciated...!!!

  • 1
    You'll need to determine how to calculate distance using your data points. There are resources available through [a google search](http://www.movable-type.co.uk/scripts/latlong.html) that should help you with the math. (I can't speak to the validity of the linked source.) Then you need to try to write the code to do the calculation yourself and update your question if you require technical assistance. – wahwahwah May 12 '17 at 19:36
  • 1
    Please, check out the help section about what questions are [on topic for SO](http://stackoverflow.com/help/on-topic). You need to supply some form of code or a detailed description of what software isn't working to expectations (or both.) – wahwahwah May 12 '17 at 19:39

1 Answers1

0

The issue with looking at pure distance between two lat,lng coordinates is that the distance one would need to drive on a road between those two points could be different. Therefore, I'd recommend using the Distance Matrix API. You could do the following:

Note: The distance matrix API is a little different about usage limits as it looks at elements instead of number of requests. Elements = number of origins * number of destinations. What you could do is start with the first two lat,lng pairs:

https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=19.8861455500,75.3164193833&destinations=19.8861096167,75.3163952833&key=MY_API_KEY

This particular request will return that the distance is 2 meters. Next you will use lat,lng pair 2 and 3 and then add this to the 2 meters you got from the previous paris of lat,lngs. You will need to check the time stamp for each lat,lng as well in order to know when 15 minutes past. You can repeat this process until 100 or 200 meters is reached, or until 15 minutes has passed. If you reach the time limit before the distance limit, you know that the driver has been within 200 meters of their starting point after driving for 15 minutes.

The free limit is 2500 elements a day, so you could run 2500 requests similar to the one above before reaching the non-billable limits. You could possibly use the Haversine formula instead to calculate the distance between two lat,lng points, but this would be the exact distance and not the distance one would need to travel on a road between the two lat,lng points, which may not be what you are looking for. That said, here is a link to a stack overflow answer describing how to use the Haversine formula with JavaScript:

Calculate distance between two latitude-longitude points? (Haversine formula)

I hope this helps!

Community
  • 1
  • 1