diff --git a/apps/api/src/maps/maps.controller.ts b/apps/api/src/maps/maps.controller.ts index 175188b..941b8e3 100644 --- a/apps/api/src/maps/maps.controller.ts +++ b/apps/api/src/maps/maps.controller.ts @@ -43,7 +43,10 @@ export class MapsController { } const profile = query.profile || 'car'; - return this.mapsService.getRoute(waypoints, profile); + const steps = query.steps === 'true'; + const locale = query.locale || 'en'; + + return this.mapsService.getRoute(waypoints, profile, steps, locale); } @Get('config') diff --git a/apps/api/src/maps/maps.service.ts b/apps/api/src/maps/maps.service.ts index d285eaf..5bbf1f1 100644 --- a/apps/api/src/maps/maps.service.ts +++ b/apps/api/src/maps/maps.service.ts @@ -22,7 +22,7 @@ export class MapsService { this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080'); } - async getRoute(waypoints: [number, number][], profile: string = 'car') { + async getRoute(waypoints: [number, number][], profile: string = 'car', steps: boolean = false, locale: string = 'en') { if (waypoints.length < 2) { throw new HttpException('At least two waypoints are required', HttpStatus.BAD_REQUEST); } @@ -57,9 +57,10 @@ export class MapsService { const payload: any = { points: ghPoints, profile: profile, - locale: 'en', + locale: locale, calc_points: true, points_encoded: true, + instructions: steps, }; // GraphHopper ONLY supports alternative routes if there are exactly 2 points (Start and End) @@ -71,7 +72,7 @@ export class MapsService { payload['alternative_route.max_share_factor'] = 0.6; } - console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl}`); + console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl} | Steps: ${steps} | Locale: ${locale}`); const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 10000 }); console.log('Routing SUCCESS'); @@ -96,7 +97,8 @@ export class MapsService { distance: alt.distance, duration: Math.round(alt.time / 1000), points: alt.points, - bbox: alt.bbox + bbox: alt.bbox, + instructions: alt.instructions // Include instructions for alternatives if requested })); return { @@ -108,7 +110,8 @@ export class MapsService { endName, points: route.points, bbox: route.bbox, - alternatives: alternatives // NEW: array of other routes + instructions: route.instructions, // Added: turn-by-turn maneuvers + alternatives: alternatives }; } catch (error) { const msg = error.response ? `GH Error: ${JSON.stringify(error.response.data)}` : `DNS/Connection Error: ${error.message}`;