I know that this is quite an old question but I thought I could add a bit of input based on my recent experiences with gmap3
and the Google Maps API.
Instead of going down the route of using the infobox
library (which I found a bit of a mare to get working with the gmap3 library) I decided to it by binding the marker click event to spawn an overlay which I could style to however I wanted.
So, I'd have my JSON with all my addresses on like so
// JSON
var data = JSON.parse('[
{
"address":"New Street, Salisbury, UK",
"content":"hello world from salisbury"
},
{
"address":"86000 Poitiers, France" ,
"content":"hello world from poitiers"
},
{
"address":"66000 Perpignam, France",
"content":"hello world from perpignam"
}
]');
I set my gmap defaults
// Gmap Defaults
$map.gmap3({
map:{
options:{
center:[46.578498,2.457275],
zoom: 5
}
}
});
I loop through my JSON and build the map
// Json Loop
$.each(data, function(key, val) {
$map.gmap3({
marker:{
values:[{
address:val.address,
events: {
click: function() {
gmap_clear_markers();
$(this).gmap3({
overlay:{
address:val.address,
options:{
content: '<div class="infobox">'+val.content+'</div>',
offset:{
y:-32,
x:12
}
}
}
});
}
}
}]
}
});
});
The gmap_clear_markers()
function triggers all other infobox(overlays) instances to be removed.
// Function Clear Markers
function gmap_clear_markers() {
$('.infobox').each(function() {
$(this).remove();
});
}
Now I can add as many addresses as I want to my JSON and it will have an infobox with just a plain div wrapper with class infobox which I can style accordingly.
I'm not sure if this is the best way to do this - I'm just saying that this has worked for me.
Here is the JSFIDDLE example