I am trying to find the midpoint using duration traffic values(n1,n2,n3) in specified departure time(timeStamp) so that all the three-person have the same travel time (midpoint by Time). I'm using Google distance matrix.
I have been passing all three locations (a,b,c) & midpoint(d) based on the distance of the three locations.
I tried finding their midpoint by subtraction(all three), average(three of them) and subtracting with (Max and Min Values of n1,n2,n3) so that there traveling time becomes equal or less than the specified time(maxTime distance b/w three of them). Then point becomes the Midpoint But I couldn't find a solution. Suggestions are much appreciated.
const maxTime = 5000;
var i = 0;
z = 0;
j = 0
//Distance Matrix Api
function getDistanceMatrix(a, b, c, d, timeStamp, googleWarnings, copyRights) {
clientMap.post(config_KEYS.DISTANCE_MATRIX_API + a + "|" + b + "|" + c + "&destinations=" + d.lat + "," + d.lng + "+&key=" + config_KEYS.GOOGLE_API_KEY + "&departure_time=" + timeStamp + "", function(gotDistanceResp, err) {
if (err) {
res.status(400).json(gotDistanceResp)
} else {
let n1 = gotDistanceResp.rows[0].elements[0].duration_in_traffic.value
let n2 = gotDistanceResp.rows[1].elements[0].duration_in_traffic.value
let n3 = gotDistanceResp.rows[2].elements[0].duration_in_traffic.value
// let minTime = Math.abs(n2 - n1)
let minTime = Math.round((n3 + n2 + n1) / 3)
if (n1 >= n2 && n1 >= n3) {
if (minTime <= maxTime) {
res.send(gotDistanceResp)
} else {
i++;
let arrayPoints = getDirectionApi(a, d, timeStamp, i)
}
} else {
if (n2 >= n1 && n2 >= n3) {
if (minTime <= maxTime) {
res.send(gotDistanceResp)
} else {
j++;
let arrayPoints = getDirectionApi(b, d, timeStamp, j)
}
} else {
if (n3 >= n1 && n3 >= n1) {
if (minTime <= maxTime) {
res.send(gotDistanceResp)
} else {
z++;
let arrayPoints = getDirectionApi(c, d, timeStamp, z)
}
} else {
res.send(gotDistanceResp)
}
}
}
}
})
}
//Get Direction Api
function getDirectionApi(a, b, timeStamp, r) {
clientMap.post(config_KEYS.DIRECTION_API + a + "&destination=" + b.lat + "," + b.lng + "&key=" + config_KEYS.GOOGLE_API_KEY + "&departure_time=" + timeStamp + "", function(route, error) {
if (route.geocoder_status == "ZERO_RESULTS" | route.status == "INVALID_REQUEST") {
res.status(400).send(route)
} else {
let googleWarnings = route.routes[0].warnings
let copyRights = route.routes[0].copyrights
let polyline = route.routes[0].overview_polyline.points
let decoded = decode(polyline)
let midPointCha = getDistanceMatrix(Location1, Location2, Location3, reversedMidArra[r])
}
})
}
from I am trying to find mid point with duration traffic (based on traffic with respect to departure time)
No comments:
Post a Comment