Fixing the overview polyline in Google Maps SDK for iOS:

BVAccurateRoutePlot – GitHub

My app NYC Taxi was using the autocomplete feature of Google Places for finding destinations easily. However, Google requires that if you are using a map anywhere in your app, it must be a Google map.

That’s when issues started to rase. I had to show a route as well on the map, and Google’s direction service only supplies us with an “overview polyline”. This is just a rough estimate of where the polyline of the route should be on the map, and often (especially for longer distances) it does not follow the road.

So, I came up with the following solution:

I wrote a class for fixing the overview polyline so it follows the road perfectly. The way I achieved this is by using Google’s Snap-To-road API. The idea is, that after receiving the overview polyline, I send all the points from it to the Snap-To-road API, which then sends back a polyline snapped to the road perfectly. The only issue was, that the API could only process 100 points per request, which is most of the time, just not enough. So my class takes care of that as well. It slices up the points into blocks of 100, and sends multiple requests. Once all the requests come back, it puts the points into the right order, and shows the snapped polyline on the map.

Please feel free to use it in your projects, and hope that it helps someone! 🙂

Grab it from GitHub!

Leave a Reply

Your email address will not be published. Required fields are marked *