I want to create a feature that contains the location history of the user itself every time it stops at a place.
For example, if the user stops at a location that I previously marked, it will display the name of the location, but if it stops at an unknown place, it will display the words “Unknown Stop”. Like the example below.
The following is an example of the location history of the user I have.
[{
"location": {
"timestamp": 1640226572000,
"fromMockProvider": false,
"speedAccuracy": 3.0999999046325684,
"speed": 2.126629114151001,
"courseAccuracy": 60.29999923706055,
"course": 335.00262451171875,
"accuracy": 4.800000190734863,
"altitudeAccuracy": 1.71183432826049805,
"altitude": 6.099546432568,
"longitude": 91.72313144,
"latitude": 3.9974028
},
"device_information": "angelica ANGELICA Redmi",
"battery": 1},{
"location": {
"timestamp": 1640226575000,
"fromMockProvider": false,
"speedAccuracy": 2.9000000953674316,
"speed": 1.7470654249191284,
"courseAccuracy": 67.80000305175781,
"course": 318.0428161621094,
"accuracy": 4.724999904632568,
"altitudeAccuracy": 1.741869330406189,
"altitude": 6.09213144568,
"longitude": 91.7316444,
"latitude": 3.9974605
},
"device_information": "angelica ANGELICA Redmi",
"battery": 1}]
//and more history in array
and the test code done, looks like it works with geolib library but has bugs in time
for (let i = 0; i < unknownArr.length; i++) {
var dataPertama = unknownArr[i]
var dataKedua = unknownArr[i + 1]
if (dataKedua != undefined) {
var selisihTotalKeduanya = hitungSelisihAngka(dataPertama.lama_unknown, dataKedua.lama_unknown)
if (selisihTotalKeduanya > 10) {
var jikaDekatToko = visitTimeArr.some(data => {
var customerData = data.customer_data
if (customerData.customer_latitude != null || customerData.customer_latitude != undefined) {
return isPointWithinRadius(
{
latitude: customerData.customer_latitude,
longitude: customerData.customer_longitude
},
{
latitude: dataPertama.start_unknown.location.latitude,
longitude: dataPertama.start_unknown.location.longitude
}, 100)
} else {
return false
}
})
var jikadiIntika = isPointWithinRadius(Strings.kordinatIntika, {
latitude: dataPertama.start_unknown.location.latitude,
longitude: dataPertama.start_unknown.location.longitude
}, 100)
if (!jikaDekatToko) {
if (!jikadiIntika) {
response.push(unknownArr[i])
} else {
var dataIntikaPertama = unknownArr.find(el => {
el.name = 'Intika'
return el !== undefined
})
response.push(dataIntikaPertama)
}
}
}
} else {
var jikadiIntika = isPointWithinRadius(Strings.kordinatIntika, {
latitude: dataPertama.start_unknown.location.latitude,
longitude: dataPertama.start_unknown.location.longitude
}, 100)
if (!jikadiIntika) {
response.push(unknownArr[i])
} else {
if (findFirstIntika) {
var dataIntikaTerakhir = unknownArr[unknownArr.length - 1]
if (dataIntikaTerakhir.name == 'Intika') {
response.push(dataIntikaPertama)
}
} else {
var dataIntikaPertama = unknownArr.find(el => {
el.name = 'Intika'
return el !== undefined
})
response.push(dataIntikaPertama)
}
}
}
}