Reputation: 1131
I have a variable: units. This contains either metric or imperial.
Ok, so in Google maps directions the following is happening:
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.WALKING,
unitSystem: UnitSystem.METRIC
};
My noobish question is: How do i change "unitSystem: UnitSystem.METRIC" into "unitSystem: units". I simply don't know what Google is expecting for as a value. Cant find it in docs either.
Upvotes: 1
Views: 2837
Reputation: 10219
As statued in https://developers.google.com/maps/documentation/javascript/distancematrix?hl=fr
unitSystem (optional) — The unit system to use when displaying distance. Accepted values are:
google.maps.UnitSystem.METRIC (default)
google.maps.UnitSystem.IMPERIAL
So I guess you could do :
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.WALKING,
unitSystem: unit == 'metric' ? google.maps.UnitSystem.METRIC : google.maps.UnitSystem.IMPERIAL
};
Upvotes: 2