Google Maps snap to roads not returning all values

1.2k Views Asked by At

I'm passing the google maps "Snap to Road" api a list of 99 points. I only get back 85 points, which means I have some points missing that won't be snapped. Is there a way to get back all the points?

Observable.fromPromise(googleMapsClient.snapToRoads({
        path: bucket,
        interpolate: interpolate
      }).asPromise()).map(routeLocations => {
        console.log(routeLocations)
}

RESPONSE FROM API:

routeLocations.query.path.split('|').length
> 99
routeLocations.json.snappedPoints.length
> 85
1

There are 1 best solutions below

1
xomena On BEST ANSWER

Certain points can be dropped from the snapped points array. Typically it happens when the points in the original path array are zigzag back and forth along a road. Unfortunately, I cannot see your path array in this question, so let me use my examples to explain this.

The path parameter describes a continuous path, so the order of points that you pass is important. As the official documentation states, the snap to road returns the most likely path taken by a vehicle, so points will get dropped if they e.g. zigzag back and forth along a road.

The following screenshot shows an example of good path where all three points can be snapped.

enter image description here

Now have a look at the example where the point 2 is dropped because it seems to not follow direction from 1 to 3, you have to go back and forward.

enter image description here

Finally, let's consider a more complex example:

52.14475625,20.79042166|52.14475625,20.79036802|52.14471345,20.79042435|52.14479246,20.79031706|52.14466408,20.79047531|52.14460647,20.79051822|52.1448369,20.79028487|52.14455544,20.79060137

Several points are dropped as shown in the following screenshot (orange points)

enter image description here

I hope my answer addresses your doubts!