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

好的,因此在Google Maps导航中发生了以下情况:

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


我的讨厌的问题是:如何将“ unitSystem:UnitSystem.METRIC”更改为“ unitSystem:units”。我根本不知道Google期望值多少。不能在文档中找到它。

最佳答案

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

关于javascript - 在 map 中获取unitSystem变量的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19562095/

10-11 01:06