google-maps-services-js
google-maps-services-js copied to clipboard
directions: Type error of via_waypoint field inside routeLeg
Hello,
When I try to use the via_waypoint field of the DirectionsLeg (that is called routeLeg inside your code for some reason) I got this error Property 'via_waypoint' does not exist on type 'RouteLeg'.ts(2339 but the data is present in the response and your documentation
an other thing that is wierd in the doc and may be related, it is said for the Directions.legs:
A separate leg will be present for each waypoint or destination specified.
But this is not the case actually if I send 0, 1, 13 waypoint i only got one leg what is the reel expected behavior ?
Environment details
NodeJS v16.14 npm package @googlemaps/google-maps-services-js v3.3.16
Steps to reproduce
- call the directions api with a waypoint
- try to use
directions.data.routes[i].legs[i].via_waypoint - you will got typescript error
Code example
import { Client } from '@googlemaps/google-maps-services-js';
const key = process.env.GOOGLE_API_KEY || '';
const client = new Client({});
export const getDistanceMatrix = (addresses: string[], departureTime?: Date): Promise<void> => client
.directions({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: TS2322
params: {
key,
origin: addresses[0],
destination: addresses[addresses.length - 1],
waypoints: addresses.slice(1, -1).map((address) => `via:${address}`),
...departureTime
? {
traffic_model: 'best_guess',
departure_time: departureTime,
}
: {},
alternatives: true,
},
})
.then((directions) => {
console.log(directions.data.routes[0].legs[0].via_waypoint)
})
const adresses = [
"25 Rue de la Marbrerie, Lille, France",
"18 Rue Jules Guesde, 59650 Villeneuve-d'Ascq, France",
"Ecole Elémentaire Voltaire-Sévigné, Rue Emile Zola Lomme, Lille, France"
]
getDistanceMatrix(adresses)
@kataiga Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:
- Support Console - If you have a support contract.
- Discord - chat with other developers
- StackOverflow - use the
google-mapstag - Google Maps Platform issue trackers
This is an automated message, feel free to ignore.