我有以下代码:
<script>
var rendererOptions = {
draggable: false
};
var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);;
var directionsService = new google.maps.DirectionsService();
var map;
var England = new google.maps.LatLng(53.7415, 1.6860);
function initialize() {
var mapOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: England
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
map.setTilt(45);
directionsDisplay.setMap(map)
directionsDisplay.setPanel(document.getElementById('directionsPanel'));
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
computeTotalDistance(directionsDisplay.directions);
});
calcRoute();
}
function calcRoute() {
var request = {
origin: 'postcode',
destination: 'postcode',
waypoints:[{location: 'waypoint postcode'}, {location: 'waypoint postcode'}, {location: 'waypoint postcode'}],
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function computeTotalDistance(result) {
var total = 0;
var myroute = result.routes[0];
for (i = 0; i < myroute.legs.length; i++) {
total += myroute.legs[i].distance.value;
}
total = total / 1000.
document.getElementById('total').innerHTML = total + ' km';
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="float:left;width:70%; height:100%"></div>
<div id="directionsPanel" style="float:right;width:30%;height 100%">
<p>Total Distance: <span id="total"></span></p>
</div>
这张地图,使用google的方向服务,显示了原点和目的地,沿途有特定的路径点。方向面板以公制单位显示所有距离。我如何改变它,使所有的距离显示在帝国单位,即英里,脚?
发布于 2013-01-18 17:22:33
单元系统 默认情况下,方向是使用原产地国家或地区的单位系统计算和显示的。(注意:使用纬度/经度坐标而不是地址表示的起源总是默认为公制单位)。例如,从“芝加哥,IL”到“多伦多,ONT”的路线将以英里为单位显示结果,而相反的路线将以公里为单位显示结果。您可以通过使用以下UnitSystem值之一在请求中显式设置一个单元系统来覆盖此单元系统:
UnitSystem.METRIC
指定度量系统的用法。距离是用公里表示的。UnitSystem.IMPERIA
L指定帝国(英语)系统的用法。距离用英里来表示。注意:此单元系统设置仅影响向用户显示的文本。方向结果还包含未向用户显示的距离值,这些值总是以米表示。
https://stackoverflow.com/questions/14404066
复制相似问题