Skalar / google_distance_matrix

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

Suggestion: add distance_in_miles method #31

Closed YGKtech closed 7 years ago

YGKtech commented 8 years ago

The "Route" class has an distance_in_meters method, but no equivalent method for retrieving the distance in miles. Setting config.units = 'imperial' will cause the distance_text method to return a string like "2.9 mi", but there is no way to access the value "2.9" as a numeric value.

Obviously it isn't hard for me to convert the values myself, but I don't see much reason not to make such an method part of the Gem.

thhermansen commented 8 years ago

Hi,

According to Google's documentation they state that:

Note: this unit system setting only affects the text displayed within distance fields. The distance fields also contain values which are always expressed in meters.

So it seems to me that the response from Google distance.value will always be in meters and thus this gem needs to do the calculation.

Feel free to provide a pull request and I'll take a look at it. For instance: You can create a class responsible for calculating feet/miles from meters and then use that class in Route and extend it with reader methods #distance_in_miles and #distance_in_feet. Remember to include specs for the code you write.

YGKtech commented 8 years ago

Interesting, I actually read their documentation before posting and I missed that line, strange that they would bother letting people configure a unit system at all if they decided to use meters as a standard unit for all the numerical values, I'm sure some very dangerous bugs have been written because of that behavior.

I'll try and put together a PR this weekend. Thanks :)

thhermansen commented 7 years ago

Closing due to inactivity :-)