Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
How to retrieve every departure and return time from user location history array with the help of geolib library with timestamp

I want to create a function which gives the final result in the form of a location history of the user when he goes and comes home. For example, I give the location history below where the 2 values ​​from the top contain the user's location history before leaving the house radius distance and 2 below it back into the house radius distance but at different times.

Here I'm using the geolib library isPointWithinRadius and the filter array, but what's taken from the whole array, is not differentiated. What's the solution?

[
     {
        "timestamp": 1641779430000,
        "latitude": 3.5970763,
        "longitude": 98.7288083
      },
      {
        "timestamp": 1641779550000, //location user in home before go out
        "latitude": 3.5970763,
        "longitude": 98.7288083
      },
      //another location history but not in home radius
      {
        "timestamp": 1641837150000, //location user back to home
        "latitude": 3.5970763,
        "longitude": 98.7288083
      },
      {
        "timestamp": 1641837210000,
        "latitude": 3.5970763,
        "longitude": 98.7288083
      },
    ]

here is my code with isBetweenTMinute function to differentiate, but it doesn't work

    var response = []
for (let i = 0; i < gpsHistory.length; i++) {
    var indexNow = gpsHistory[i]
    var indexNext = gpsHistory[i + 1]
    if (indexNext != undefined) {
        var pointAwal = { latitude: indexNow.location.latitude, longitude: indexNow.location.longitude }
        const isRange = isPointWithinRadius(pointAwal, { latitude: indexNext.location.latitude, longitude: indexNext.location.longitude }, 100)
        if (isRange) {
            var jumlahVisit = []
            var arrData = gpsHistory.filter((item, index) => {
                if (isBetweenTMinute(item.location.timestamp, indexNow.location.timestamp)) {
                    if (isPointWithinRadius(pointAwal, { latitude: item.location.latitude, longitude: item.location.longitude }, 100)) {
                        return true
                    }
                }
                return false
            })
            response.push(arrData)
        }
    }
}
console.log(response)


function isBetweenTMinute(date1, date2) {
    var dateKurang = (date2 - date1) / 1000;
    var minute = dateKurang / 60
    if (minute < 10) {
        return true
    } else {
        return false
    }
}


    //result that i want
    [
        [0,1],//history location in home radius before user go out
        [2, 3, 4, 5, 6,7,8,9] //another history outside home radius
        [10,11] //Location history when the user returns to the radius of the house.
    ]
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!