GUnload is null or undefined using Directions Service
Posted
by
user1677756
on Stack Overflow
See other posts from Stack Overflow
or by user1677756
Published on 2012-09-17T14:07:59Z
Indexed on
2012/09/18
3:38 UTC
Read the original article
Hit count: 208
google-maps-api-3
I'm getting an error using Google Maps API V3 that I don't understand. My initial map displays just fine, but when I try to get directions, I get the following two errors:
Error: The value of the property 'GUnload' is null or undefined, not a Function object
Error: Unable to get value of the property 'setDirections': object is null or undefined
I'm not using GUnload anywhere, so I don't understand why I'm getting that error. As far as the second error is concerned, it's as if something is wrong with the Directions service.
Here is my code:
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);
}
});
}
I'm not very savvy with javascript, so I could have made some sort of error there. I appreciate any help I can get.
© Stack Overflow or respective owner