Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: add distance_in_miles method #31

Closed
YGKtech opened this issue Aug 11, 2016 · 3 comments
Closed

Suggestion: add distance_in_miles method #31

YGKtech opened this issue Aug 11, 2016 · 3 comments

Comments

@YGKtech
Copy link

YGKtech commented Aug 11, 2016

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
Copy link
Member

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
Copy link
Author

YGKtech commented Aug 11, 2016

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
Copy link
Member

Closing due to inactivity :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants