From 03f7aad437b070c0e906a17aaf05b64add511565 Mon Sep 17 00:00:00 2001 From: mgik Date: Tue, 2 Jun 2026 17:18:54 +0600 Subject: [PATCH] refactor: use the correct order of the latitude and longitude in OSRM api OSRM API's routing service returns coordinates in the order of longitude first and latitude second. For some reason the OSRM's docs don't explicitly specify that, but you can check that by sending a request to their api endpoint. Currently the trip service's (*OsrmApiResponse).ToProto() method parses the data in incorrect order, thus making latitude value be longitude and vice versa. Additionally, react-leaflet's Polyline component expects to receive values for 'positions' attribute in the order of latitude first and longitude second. (https://react-leaflet.js.org/docs/api-components/#polyline) 'LatLngExpression' type's name hints to the correct order. --- services/trip-service/pkg/types/types.go | 4 ++-- web/src/components/DriverMap.tsx | 2 +- web/src/components/RiderMap.tsx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/trip-service/pkg/types/types.go b/services/trip-service/pkg/types/types.go index cd155fc..8699675 100644 --- a/services/trip-service/pkg/types/types.go +++ b/services/trip-service/pkg/types/types.go @@ -18,8 +18,8 @@ func (o *OsrmApiResponse) ToProto() *pb.Route { coordinates := make([]*pb.Coordinate, len(geometry)) for i, coord := range geometry { coordinates[i] = &pb.Coordinate{ - Latitude: coord[0], - Longitude: coord[1], + Longitude: coord[0], + Latitude: coord[1], } } diff --git a/web/src/components/DriverMap.tsx b/web/src/components/DriverMap.tsx index a478611..88fe5a7 100644 --- a/web/src/components/DriverMap.tsx +++ b/web/src/components/DriverMap.tsx @@ -111,7 +111,7 @@ export const DriverMap = ({ packageSlug }: { packageSlug: CarPackageSlug }) => { const parsedRoute = useMemo(() => requestedTrip?.route?.geometry[0]?.coordinates - .map((coord) => [coord?.longitude, coord?.latitude] as [number, number]) + .map((coord) => [coord?.latitude, coord?.longitude] as [number, number]) , [requestedTrip]) // destination is the last coordinate in the route diff --git a/web/src/components/RiderMap.tsx b/web/src/components/RiderMap.tsx index 4ee3d93..df644b9 100644 --- a/web/src/components/RiderMap.tsx +++ b/web/src/components/RiderMap.tsx @@ -75,7 +75,7 @@ export default function RiderMap({ onRouteSelected }: RiderMapProps) { console.log(data) const parsedRoute = data.route.geometry[0].coordinates - .map((coord) => [coord.longitude, coord.latitude] as [number, number]) + .map((coord) => [coord.latitude, coord.longitude] as [number, number]) setTrip({ tripID: "", @@ -237,4 +237,4 @@ export default function RiderMap({ onRouteSelected }: RiderMapProps) { ) -} \ No newline at end of file +}