Reputation: 4559
I am dynamically loading images to use in google maps.
I do so with the following code
var markerImage = new google.maps.MarkerImage('../myurl');
var marker = new google.maps.Marker({ position: latlng, map: map, icon: markerImage, title: values[2] });
The problem is if that url is not valid, no errors are thrown, there are no exceptions. Also I cant check against the value (null or anything).
If the url is invalid the image doesnt show up. If the is valid it does show up. I tried the get.Icon method on marker but that just shows
anchor: undefined, origin: undefined, scaledSize: undefined, size: undefined, url:"../myurl"
Upvotes: 1
Views: 192
Reputation: 3873
Try loading an image using your url and listening for onload
and onerror
before passing it to the google.maps.MarkerImage
constructor:
var img = new Image();
img.onload = function () {
// sweet, let's do this!
}
img.onerror = function () {
// oops, something went wrong!
}
img.src = 'yoururl/whatever.png';
Upvotes: 2