Skalar / google_distance_matrix

Ruby client for The Google Distance Matrix API.
MIT License
57 stars 45 forks source link

Support encoded polyline as request parameters #20

Closed kofronpi closed 8 years ago

kofronpi commented 8 years ago

It would be great if the google_distance_matrix would support encoded polylines as request parameters, which allow to query for more locations in a single API call:

https://developers.google.com/maps/documentation/distance-matrix/intro#RequestParameters

thhermansen commented 8 years ago

I agree that would be great. Feel free to see if you can implement it and submit a pull request. Remember to write rspec tests for your submitted code.

I think a good way to do it is to have one class handle the conversion between lat/lng to encoded polylines. Then let Place#to_param use that class to return it's lat/lng values encoded instead of lat/lng numeric value.

Place#to_param already receives options from UrlBuilder#params and the UrlBuilder has access to the configuration object so we can add one option to the config to let users either use encoded values or the old lat/lng values like we have it today.

Edit: Maybe a better approach is to let the UrlBuilder take all places and encode them in to one encoded polyline to save characters in the URL. The API doc states that you can have multiple enc: separated by the pipe character in origins/destinations, but maybe it is better to simply encode them all in to one polyline?

Suggestions for todos

kofronpi commented 8 years ago

@thhermansen Would you advise leveraging an existing gem as a dependency to encode/decode polylines such as https://github.com/joshuaclayton/polylines or not ?

I'll have a look to see if I can free some time to submit a PR.

thhermansen commented 8 years ago

I took this one as a Monday challenge and think I have something which works. Please take a look at #24.

Please try it out and see if it works as expected and let me know how it goes as a comment in that pull request :)