I'd like to return all the countries from a google.maps.DirectionsResult object after routing from A to B. The response does not include information about this directly, but in the instructions it sometimes says Entering Germany as an example.
Now my function goes over the steps array and accumulates the kms until it reaches an 'Entering...' instruction, then saves the entry and goes on with the new country.
This works for some countries in Europe but not all of them. For example: Istanbul to Zagreb does not contain any information about crossing the border which means this way won't work.
Has anybody run into this before? Or do you know a solution for this?
Here is a very basic / non-optimized implementation of what I mentioned in my comment (using DistanceMatrix Service).
A cleaner implementation would be to use promises with the DistanceMatrix Service since you need to split all steps locations into chunks of max 25 locations then reduce the list to unique countries. What I did is really just a proof of concept.
Also (as you can see from the output of the below script) it looks like sometimes, the string after the last comma in the DistanceMatrix reponse isn't the country name but something else (for example the 6530 in the below output), or it can contain a postal code and the country name (that's what I found out running just a few tests, you might find more exceptions).
Other than that, the output seems correct. Again, beware of the costs of such an implementation (DistanceMatrix + Directions API + basic map usage).