1

我有一个变量:单位。这包含公制或英制。

好的,所以在谷歌地图方向中发生了以下情况:

var request = {
    origin:start,
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.WALKING,
    unitSystem: UnitSystem.METRIC
};

我的问题是:如何将“unitSystem:UnitSystem.METRIC”更改为“unitSystem:units”。我根本不知道 Google 期望的价值是什么。在文档中也找不到。

4

1 回答 1

2

https://developers.google.com/maps/documentation/javascript/distancematrix?hl=fr中所述

unitSystem(可选)- 显示距离时使用的单位系统。可接受的值为:

google.maps.UnitSystem.METRIC(默认)

google.maps.UnitSystem.IMPERIAL

所以我想你可以这样做:

var request = {
    origin:start,
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.WALKING,
    unitSystem: unit == 'metric' ? google.maps.UnitSystem.METRIC : google.maps.UnitSystem.IMPERIAL
};
于 2013-10-24T09:40:20.277 回答