Google map驱车路线

lalaguan 2009-12-01 10:10:35
在下面这个示例中,如果A点与B点之间没有可行的路线,那么他会返回什么呢?
我应该怎样在它显现出来之前根据某个东西判断他到底有没有找到路线呢?
比如两个孤岛之间,有时候让你游泳都会让你游过去,有时候就不会提示出路线了

请高手帮忙,谢谢!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<title>Google Maps JavaScript API Example: Simple Directions</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA"
type="text/javascript"></script>
<script type="text/javascript">
// Create a directions object and register a map and DIV to hold the
// resulting computed directions

var map;
var directionsPanel;
var directions;

function initialize() {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(42.351505,-71.094455), 15);
directionsPanel = document.getElementById("route");
directions = new GDirections(map, directionsPanel);
directions.load("from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)");
}
</script>
</head>

<body onload="initialize()">
<div id="map_canvas" style="width: 70%; height: 480px; float:left; border: 1px solid black;"></div>
<div id="route" style="width: 25%; height:480px; float:right; border; 1px solid black;"></div>
<br/>
</body>
</html>
...全文
132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lalaguan 2009-12-04
  • 打赏
  • 举报
回复
哈哈,我后来找到这个方法了。谢谢你的回复。
[Quote=引用 7 楼 chidaidl 的回复:]
如果GDirections查不到结果的话,会返回一个Status Code [G_GEO_UNKNOWN_DIRECTIONS= 604] 。你可以注册一个onError回调函数来读取statuscode,然后做相应处理:例子如下:
[/Quote]
moliu 2009-12-04
  • 打赏
  • 举报
回复
谈笑有鸿儒往来无白丁
chidaidl 2009-12-04
  • 打赏
  • 举报
回复

如果GDirections查不到结果的话,会返回一个Status Code [G_GEO_UNKNOWN_DIRECTIONS= 604] 。你可以注册一个onError回调函数来读取statuscode,然后做相应处理:例子如下:


gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "error", handleErrors);
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS)
alert("Could not find a Direction");
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}
yichijianfang 2009-12-02
  • 打赏
  • 举报
回复
是错了!!!
happy664618843 2009-12-02
  • 打赏
  • 举报
回复
51ditu去看下
weiwei07062354 2009-12-02
  • 打赏
  • 举报
回复
你该去google map那个板块,
lalaguan 2009-12-02
  • 打赏
  • 举报
回复
我去那里提过,但是那里没有这里人气高。
xiongzhijian 2009-12-02
  • 打赏
  • 举报
回复
d
lalaguan 2009-12-01
  • 打赏
  • 举报
回复
难道说这个问题提错地方了?郁闷!

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧