Search code examples
javascriptrestmapshere-api

HERE map does not show a local image with a marker


I cannot see a local image in my map marker, I am using the following code:

var image = "./Resources/Images/SearchResult.png"; 
    var pushpin = new H.map.Icon(image, {
        size: {
            w: 20,
            h: 34
        }});
    var marker = new H.map.Marker({
        lat: 19.36506869690797,
        lng: -99.17162822555392
    },{
        icon: pushpin
      });
    map.addObject(marker);

Solution

  • If you need to add local image, you can use DOM Marker like below code:

    var kMarkerSearchResult  = "file:///resources/images/SearchResult.png";    
    var markerHTML = '<div>' + '<img src="' + kMarkerSearchResult +'">' + '</div>';
    
    var domIcon = new H.map.DomIcon(markerHTML);
    var bearsMarker = new H.map.DomMarker({lat: 53.430, lng: -2.961 }, { icon: domIcon });
    
    map.addObject(bearsMarker);
    

    Don't forget to put "file: ///" at the beginning of the path.