在我的代码中,我试图找出如何将KM转换成Google地图中的里程。
基本上,我使用Google显示两个位置之间的距离和时间,一切都很好,但我的问题是,它显示的距离是公里,而不是英里。
有什么额外的mapOptions,我可以用以英里为单位来代替吗?
这是我的全部代码:
http://jsfiddle.net/1on2yumf/1/
问题是,它显示的距离,英里,在摇铃,但它显示的距离,公里在我的网页,这是我所经历过的最奇怪的事情!
我的代码与上面在jsfiddle中显示的代码相同。
整个法典:
<script>
(function () {
var directionsService = new google.maps.DirectionsService(),
directionsDisplay = new google.maps.DirectionsRenderer(),
createMap = function (start) {
var travel = {
origin : (start.coords)? new google.maps.LatLng(start.lat, start.lng) : start.address,
destination : "<?php echo $CUpostCode; ?>",
travelMode : google.maps.DirectionsTravelMode.DRIVING
// Exchanging DRIVING to WALKING above can prove quite amusing :-)
},
mapOptions = {
zoom: 2,
// Default view: downtown Stockholm
center : new google.maps.LatLng(59.3325215, 18.0643818),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("map-directions"));
directionsService.route(travel, function(result, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
};
// Check for geolocation support
if (navigator.geolocation) {
window.onload = (function (position) {
// Success!
createMap({
coords : true,
//lat : position.coords.latitude,
//lng : position.coords.longitude
lat : <?php echo $curLat; ?>,
lng : <?php echo $curLon; ?>
});
},
function () {
// Gelocation fallback: Defaults to Stockholm, Sweden
createMap({
coords : true,
//lat : position.coords.latitude,
//lng : position.coords.longitude
lat : <?php echo $curLat; ?>,
lng : <?php echo $curLon; ?>
});
}
);
}
else {
// No geolocation fallback: Defaults to Lisbon, Portugal
createMap({
coords : true,
//lat : position.coords.latitude,
//lng : position.coords.longitude
lat : <?php echo $curLat; ?>,
lng : <?php echo $curLon; ?>
});
}
})();
</script> 和标题中的这个:
<script src="http://maps.google.se/maps/api/js?sensor=false"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>如有任何建议,将不胜感激。
发布于 2014-12-31 09:03:00
我建议明确定义这些指标。
只需在此代码中添加一行unitSystem: google.maps.UnitSystem.METRIC,如下所示:
var travel = {
origin : (start.coords)? new google.maps.LatLng(start.lat, start.lng) : start.address,
destination : "<?php echo $CUpostCode; ?>",
travelMode : google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.IMPERIAL
// Exchanging DRIVING to WALKING above can prove quite amusing :-)
},https://stackoverflow.com/questions/27718513
复制相似问题