gpt4 book ai didi

javascript - 谷歌地图API : Gdirections is Not defined

转载 作者:行者123 更新时间:2023-12-02 19:59:45 24 4
gpt4 key购买 nike

我的 map 主要是渲染的,但我在 firebug 中不断收到错误,指出 GDirections 未定义。这是 firebug 中的完整错误:

GDirections is not defined
initialize()?from=...ions%21 (line 39)
(?)()?from=...ions%21 (line 89)
F()jquery.min.js (line 19)
$(G=[function(), function()], K=function(), F=undefined)jquery.min.js (line 12)
F()jquery.min.js (line 19)
F()jquery.min.js (line 19)
[Break On This Error] gdir = new GDirections(map, document.getElementById("directions"));

似乎我没有正确引用 API。

另外,不用担心 {{ addressable.lat }} 的奇怪语法。我从 Django 模板调用它,并且只传递一个值,在本例中为纬度。这是代码:

 <script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>

<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng({{ addressable.lat }}, {{ addressable.lon }});
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"{{ addressable.company }}"});

gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);

setDirections("Pittsburgh, PA", "{{ addressable.address}}", "en_US");
}

function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress,
{ "locale": locale });
}

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_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

else alert("An unknown error occurred.");

}

function onGDirectionsLoad(){
// Use this function to access information about the latest load()
// results.
}
</script>

最佳答案

GDirections 是 API 2 的一部分,但其余代码采用 API 3 语法。您应该使用 DirectionsService反而。此外,您还引用了 GEvent,但这也不起作用。

关于javascript - 谷歌地图API : Gdirections is Not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8162464/

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