gpt4 book ai didi

google-maps - 在谷歌地图中计算距离和持续时间

转载 作者:行者123 更新时间:2023-12-04 06:57:14 24 4
gpt4 key购买 nike

我需要使用谷歌地图(印度境内)通过地理编码计算距离和持续时间。任何代码或解决方案都会有所帮助。

最佳答案

您可能想使用 GDirections.getDistance()GDirections.getDuration()方法,如下例所示:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps GDirections Demo</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false"
type="text/javascript"></script>
</head>
<body onunload="GUnload()" style="font-family: Arial; font-size: 12px;">

<div id="map" style="width: 400px; height: 300px"></div>
<div id="duration">Duration: </div>
<div id="distance">Distance: </div>

<script type="text/javascript">

var map = new GMap2(document.getElementById("map"));
var directions = new GDirections(map);

directions.load("from: Chennai, India to: Mumbai, India");

GEvent.addListener(directions, "load", function() {

// Display the distance from the GDirections.getDistance() method:
document.getElementById('distance').innerHTML +=
directions.getDistance().meters + " meters";

// Display the duration from the GDirections.getDuration() method:
document.getElementById('duration').innerHTML +=
directions.getDuration().seconds + " seconds";
});
</script>
</body>
</html>

Google Maps GDirections Demo

关于google-maps - 在谷歌地图中计算距离和持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2408028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com