如何访问Google地图中的各个元素?
有没有办法通过API执行此操作,还是我必须解析DOM并分别拉出元素(例如距离,时间,方向)? API的第2版或第3版没问题。
示例:
<div jstcache="6" style="text-align: right; padding-bottom: 0.3em;"
jseval="this.innerHTML = $Route.summaryHtml">38.9 mi (about 40 mins)</div>
我想要Javascript计算的距离(例如,38.9英里)。如果API中不存在任何内容,我将手动解析它。
谢谢, 标记
注意:这是我正在使用的完整示例网站:http://code.google.com/intl/en-EN/apis/maps/documentation/examples/directions-advanced.html
使用简化解决方案进行更新:
对于那些需要它的人来说,这是一个非常简单的完整HTML页面,我可以从Cannonade发布的示例中细化出来。这删除了所有样式和其他脚本:
<html>
<head>
<script src="maps.google.com/maps?file=api&v=2.x&a…; type="text/javascript"></script>
<script>
function initialize()
{
alert("loading ...");
if (GBrowserIsCompatible())
{
var wp = new Array ();
wp[0] = new GLatLng(32.742149,119.337218);
wp[1] = new GLatLng(32.735347,119.328485);
directions = new GDirections(); directions.loadFromWaypoints(wp);
GEvent.addListener(directions, "load", function()
{
alert(directions.getDuration().seconds);
});
}
else
{
alert("Sorry, the Google Maps API is not compatible with this browser");
}
}
</script>
</head>
<body onload="initialize();" onunload="GUnload();"></body>
</html>
将代码示例放入index.html,您将被设置。
答案 0 :(得分:0)
您可以在回复中获取GDirections :: loadFromWaypoints请求的各个属性。