Javascript GUnload为null或未使用Directions服务定义

Javascript GUnload为null或未使用Directions服务定义,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我在使用Google Maps API V3时遇到了一个错误,我不明白。我的初始地图显示得很好,但当我尝试获取方向时,会出现以下两个错误: 错误:属性“GUnload”的值为null或未定义,不是函数对象 错误:无法获取属性“setDirections”的值:对象为null或未定义 我没有在任何地方使用枪弹,所以我不明白为什么我会犯这样的错误。至于第二个错误,就好像方向服务出了问题 这是我的密码: var directionsDisplay; var directionsService = ne

我在使用Google Maps API V3时遇到了一个错误,我不明白。我的初始地图显示得很好,但当我尝试获取方向时,会出现以下两个错误:

错误:属性“GUnload”的值为null或未定义,不是函数对象

错误:无法获取属性“setDirections”的值:对象为null或未定义

我没有在任何地方使用枪弹,所以我不明白为什么我会犯这样的错误。至于第二个错误,就好像方向服务出了问题

这是我的密码:

var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize(address) {

  directionsDisplay = new google.maps.DirectionsRenderer();
  var geocoder = new google.maps.Geocoder();
  var latlng = new google.maps.LatLng(42.733963, -84.565501);
  var mapOptions = {
   center: latlng,
   zoom: 15,
   mapTypeId: google.maps.MapTypeId.ROADMAP
 };
 map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
 geocoder.geocode({ 'address': address }, function (results, status) {
   if (status == google.maps.GeocoderStatus.OK) {
     map.setCenter(results[0].geometry.location);
     var marker = new google.maps.Marker({
       map: map,
       position: results[0].geometry.location
     });
   } else {
     alert("Geocode was not successful for the following reason:  " + status);
   }
 });
 directionsDisplay.setMap(map);
}

function getDirections(start, end) {
 var request = {
  origin:start,
  destination:end,
  travelMode: google.maps.TravelMode.DRIVING
 };
 directionsService.route(request, function(result, status) {
  if (status == google.maps.DirectionsStatus.OK) {
    directionsDisplay.setDirections(result);
  } else {
    alert("Directions cannot be displayed for the following reason:  " + status);
  }
 });
}

我对javascript不是很精通,所以我可能在那里犯了一些错误。我很感激能得到的任何帮助。

GUnload是谷歌地图API v2版的东西。如果您收到一个错误,说它是未定义的,这意味着您的一些代码(或您的应用程序中包含的代码)正在使用它,而您使用的是Google Maps API v3,它没有提供它


在没有看到更多上下文的情况下,无法对setDirections问题发表评论,但很可能是因为在加载API代码之前尝试调用它。

请告诉我们如何加载API。我实际上是在.NET代码中这样做的:Dim url As New StringBuilder(“)url.Append(ConfigurationManager.AppSettings(BusinessLogicLayer.Common.GoogleMapsApiKey))url.Append(“&sensor=false”)Page.ClientScript.RegisterClientScriptInclude(businesslogicalyer.Common.GoogleMapsInclude,url.ToString)它最终是:不必管.NET了。重要的是进入浏览器的内容。只看javascript。