Reputation: 117
Hi I am trying to add an image into a google maps infoWindow, my code is like this a script
var ContactUs = function () {
return {
//main function to initiate the module
init: function () {
var map;
$(document).ready(function(){
map = new GMaps({
div: '#map',
lat: -13.004333,
lng: -38.494333,
});
var marker = map.addMarker({
lat: -13.004333,
lng: -38.494333,
title: 'Loop, Inc.',
infoWindow: {
content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107"
}
});
marker.infoWindow.open(map, marker);
});
}
};
}();
Then in my HTML it gets called like this:
<div class="row-fluid">
<div id="map" class="gmaps margin-bottom-40" style="height:400px;"></div>
</div>
I tried adding an image tag into the script file but it doesn't work, I understand I have to add some code in the html file instead but not sure as to what?
Upvotes: 1
Views: 13466
Reputation: 516
Use this, I tried this one in my app:
infoWindow.setContent(html);
infoWindow.open(map, marker);
Instead of:
infoWindow: {
content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107"
}
Upvotes: 0
Reputation: 161334
You add your HTML to reference the image in the InfoWindow "content"
var marker = map.addMarker({
lat: -13.004333,
lng: -38.494333,
title: 'Loop, Inc.',
infoWindow: {
content: "<b>Loop, Inc.</b> 795 Park Ave, Suite 120<br>San Francisco, CA 94107<br><img src='myimage.jpg' alt='image in infowindow'>"
}
});
Above assumes the image "myimage.jpg" in the local directory. You can also use an absolute URL. Be careful of mixing " (double quotes) and ' (single quotes).
Upvotes: 4