This question already has an answer here:
- Using a Relative Path in Javascript to Set Google Map Icon 1 answer
I am using Google's Javascript APi v.3.0 to develop a web app. I want to be able to display custom markers, but they don't show up when I try to add them. I've written a helper function in Javascript to display a custom marker:
function addCustomMarker(iconFile,iconTitle,lat,lng){
var loc = new google.maps.LatLng(lat,lng);
var marker = new google.maps.Marker({
position:loc,
icon:iconFile,
title: iconTitle,
zIndex:2
});
marker.setMap(map);//Where map is a google.maps.Map already defined
}
I'm currently testing locally and my file structure sort of looks like:
- /Maps Application
- map.htm
- /Images
- markerImage.png
Elsewhere in the html file, I then call the javascript function like:
addCustomMarker('Images/markerImage.png', 'Custom Marker', 20, 50);
However, this does not work. No marker is displayed. If I comment out the "icon: markerIcon," line, then the default marker is displayed, which tells me that it can't find the image file.
Is there a way to reference marker images from a relative path like I am trying to do? I've tried './Images/markerImage.png' and '/Images/markerImage.png' as well, and neither work.