Search code examples
iosswiftgoogle-maps-api-3google-maps-sdk-ios

iOS Google Maps direction api giving wrong distorted path


I have attached a screenshot in which path has been drawn between two points. But the path is very strange. You can look that source has two ways to to go , one reaches completely to destination and the other does not.

This is the (https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJIQBpAG2ahYAR_6128GcTUEo&destination=place_id:ChIJVVVVVYx3j4ARP-3NGldc8qQ&key=xxxxxx) that I am using to draw path with directions api.

I do not understand why this path is so uncommon. It does look like the shortest path between two points. And why there isn't a single instead of two lines in parallel.

Any help is appreciated. Thanks


Solution

  • Add alternatives=false in your request.

    For example

    (https://maps.googleapis.com/maps/api/directions/json?origin=place_id:ChIJIQBpAG2ahYAR_6128GcTUEo&destination=place_id:ChIJVVVVVYx3j4ARP-3NGldc8qQ&alternatives=false&key=xxxxxx)

    It will give you single path.