feat: refs #7882 Added osrmservice #3281
|
@ -38,7 +38,9 @@ module.exports = Self => {
|
|||
const concatCoords = coords
|
||||
.map(coord => `${coord.longitude},${coord.latitude}`)
|
||||
.join(';');
|
||||
const response = await axios.post(`${locationiqConfig.url}${concatCoords}?key=${locationiqConfig.key}`);
|
||||
const response = await axios.post(`
|
||||
${locationiqConfig.url}optimize/driving/${concatCoords}?key=${locationiqConfig.key}
|
||||
`);
|
||||
const tolerance = locationiqConfig.tolerance;
|
||||
|
||||
for (waypoint of response.data.waypoints) {
|
||||
|
@ -46,10 +48,14 @@ module.exports = Self => {
|
|||
const latitude = waypoint.location[1];
|
||||
|
||||
const matchedAddress = coords.find(coord =>
|
||||
!coord.position &&
|
||||
Math.abs(coord.latitude - latitude) <= tolerance &&
|
||||
Math.abs(coord.longitude - longitude) <= tolerance
|
||||
);
|
||||
if (matchedAddress) matchedAddress.position = waypoint.waypoint_index;
|
||||
if (matchedAddress)
|
||||
matchedAddress.position = waypoint.waypoint_index;
|
||||
else
|
||||
console.log(`Las coordenadas no se han podido asociar: ${latitude} | ${longitude}`);
|
||||
}
|
||||
coords.sort((a, b) => {
|
||||
const posA = a.position !== undefined ? a.position : Infinity;
|
||||
|
@ -58,9 +64,9 @@ module.exports = Self => {
|
|||
});
|
||||
// Temporal para abrir en maps
|
||||
const coordsString = coords
|
||||
.map(item => `${item.latitude},${item.longitude}`)
|
||||
.join('/');
|
||||
console.log(`https://www.google.es/maps/dir/${coordsString}`);
|
||||
.map(item => `point=${item.latitude},${item.longitude}`)
|
||||
.join('&');
|
||||
console.log(`https://graphhopper.com/maps/?${coordsString}&profile=small_truck`);
|
||||
// ---------
|
||||
return coords;
|
||||
} catch (err) {
|
||||
|
@ -69,6 +75,8 @@ module.exports = Self => {
|
|||
throw new UserError('No trips found because input coordinates are not connected');
|
||||
case 'NotImplemented':
|
||||
throw new UserError('This request is not supported');
|
||||
case 'InvalidOptions':
|
||||
throw new UserError('Invalid options or too many coordinates');
|
||||
default:
|
||||
throw err;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
CREATE TABLE `vn`.`locationiqConfig` (
|
||||
`id` int(10) unsigned NOT NULL,
|
||||
`url` varchar(100) NOT NULL,
|
||||
`key` varchar(100) NOT NULL,
|
||||
`tolerance` decimal(6,6) NOT NULL DEFAULT 0,
|
||||
`url` varchar(100) NOT NULL COMMENT 'Dirección base de la API',
|
||||
`key` varchar(100) NOT NULL COMMENT 'Access token',
|
||||
`tolerance` decimal(6,6) NOT NULL DEFAULT 0 COMMENT 'Tolerancia entre las coordenadas enviadas y las retornadas',
|
||||
`maxCoordsRequest` int(10) unsigned DEFAULT NULL COMMENT 'Número máximo de coordenadas por petición',
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `locationiqConfig_check` CHECK (`id` = 1)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
|
@ -392,5 +392,6 @@
|
|||
"The raid information is not correct": "La información de la redada no es correcta",
|
||||
"There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero",
|
||||
"No trips found because input coordinates are not connected": "No se encontraron rutas porque las coordenadas de entrada no están conectadas",
|
||||
"This request is not supported": "Esta solicitud no es compatible"
|
||||
"This request is not supported": "Esta solicitud no es compatible",
|
||||
"Invalid options or too many coordinates": "Opciones invalidas o demasiadas coordenadas"
|
||||
}
|
Loading…
Reference in New Issue