3

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
xomena
  • 31,125
  • 6
  • 88
  • 117
Matt Westlake
  • 3,499
  • 7
  • 39
  • 80
  • 2
    Please provide a [mcve] that demonstrates your issue (including sample data). – geocodezip Feb 10 '18 at 01:04
  • 1
    Can you also provide a dataset of your points? It is difficult to analyze the issue without any data that demonstrate the problem. – xomena Feb 11 '18 at 10:11

1 Answers1

5

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!

xomena
  • 31,125
  • 6
  • 88
  • 117
  • Absolutely... Some of the points were while we were stopped at a stoplight, and some of them were so close together that it "snapped" to the same spot on the road. Thank you for the explanation. – Matt Westlake Feb 12 '18 at 14:21