Closed YGKtech closed 7 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.
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 :)
Closing due to inactivity :-)
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.