Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda