2026-04-12-1
This commit is contained in:
@@ -10,18 +10,25 @@ export class MapsService {
|
||||
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
|
||||
}
|
||||
|
||||
async getRoute(from: [number, number], to: [number, number]) {
|
||||
async getRoute(waypoints: [number, number][], profile: string = 'car') {
|
||||
if (waypoints.length < 2) {
|
||||
throw new HttpException('At least two waypoints are required', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
try {
|
||||
// GraphHopper expects [lng, lat] order
|
||||
const ghPoints = waypoints.map(wp => [wp[1], wp[0]]);
|
||||
|
||||
const payload: any = {
|
||||
points: [[from[1], from[0]], [to[1], to[0]]],
|
||||
profile: 'car',
|
||||
points: ghPoints,
|
||||
profile: profile,
|
||||
locale: 'en',
|
||||
calc_points: true,
|
||||
points_encoded: true,
|
||||
};
|
||||
|
||||
console.log(`Routing Request: ${from} -> ${to} via ${this.graphHopperUrl}`);
|
||||
const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 5000 });
|
||||
console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl}`);
|
||||
const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 10000 });
|
||||
|
||||
console.log('Routing SUCCESS');
|
||||
const route = response.data.paths[0];
|
||||
|
||||
Reference in New Issue
Block a user