在映射中获取单位系统的变量值

Taking the value of a variable for unitSystem in maps

本文关键字:系统 变量值 单位 获取 映射      更新时间:2023-09-26

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

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

var request = {
    origin:start,
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.WALKING,
    unitSystem: UnitSystem.METRIC
};
我的菜鸟问题是:如何将"单位系统:单位系统

.公制"更改为"单位系统:单位"。我根本不知道谷歌对价值的期望是什么。在文档中也找不到它。

如 https://developers.google.com/maps/documentation/javascript/distancematrix?hl=fr 年雕像

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

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
};