Hey all,
I’m not a developer, but a designer. So don’t be too harsh on me.
I’m trying out the Routing API, and I want to get GeoJSON back to create a poly line.
But I get “longitude” and “latitude” written out in each point. Is there a way to convert to GeoJSON?
Cheers,
Paul
maloleps
(Przemek Malolepszy)
December 23, 2019, 4:33pm
#2
Hi Paul,
Yes, raw Routing API returns only points.
With SDK for Web you can easily transform the response to GeoJSON.
Example on how to achieve that: https://developer.tomtom.com/maps-sdk-web-js/functional-examples#examples,code,static-route.html
2 Likes
Thanks Maloleps.
In the end I did not need GeoJSON. I just had to remove the strings longitude & latitude.
A dev on my team helped me with this code snippet
const tomTomRouteFormatToGEOJsonIsh: object => Array = tomTomData => {
const outputArray = [];
const route = tomTomData.routes[0];
route.legs.forEach(leg => {
leg.points.forEach(point => {
const outputPoint = [point.latitude, point.longitude];
outputArray.push(outputPoint);
});
});
return outputArray;
};
Cheers,
Paul
2 Likes