how can i use a "for each" function for add more addresses on this gmap script?
$("#mydiv").gMap({
markers: [{
address: document.getElementById("address").innerHTM开发者_如何学运维L,
html: document.getElementById("text").innerHTML,
popup: true
}],
zoom: 4
});
This isn't for each iteration but you can do your work as well.
Let's say that you have a json object.
var markers = eval(jsonMarkers);
for (id in markers) {
var nMarker = createMarker(markers[id], mapID);
map.addOverlay(nMarker);
}
function createMarker(pointData, mapID) {
var latlng = new GLatLng(pointData.Latitude, pointData.Longitude);
var marker = new GMarker(latlng );
return marker;
}
I hope this hepls
so i've try with:
$(function () {
var myJSON
$("#address span").each(function () {
myJSON = [{ address: $("#address span").html,
html: $("#txt span").html,
popup: true
}] ;
});
if ($("#address").html != "") {
$("#mymap").gMap({
markers: myJSON,
zoom: 4
});
}
});
I retrieve data from db access and with asp.net code write in my 2 div elements the addresses and data that i need to show ... but i got errors :\ my divs are fill correct ...
so I had to do the same thing: this is using ajax, but the concept is the same. Note the array of objects being passed into the gmaps. Link to my question
精彩评论