First let me explain. I have several addresses on the page that I put into an array. I then want to go over that array and replace each address with its longitude and latitude.
The problem is my attempt only runs one time.
$(function () {
var addr = 0;
var shops = [];
var addressPoint;
var latlng = new google.maps.LatLng(38, -97);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
window.onload = function () {
var options = [];
$('.address').each(function () {
if (!$(this).is(":empty")) {
options.push($(this).text());
txt = $(this).text();
} else {}
});
alert(options);
$.each(options, function () {
var addr = ("'" + this + "'");
searchAddr(addr);
});
function searchAddr(addr) {
$('#map_canvas').gmap({
'callback': function () {
var self = this;
alert(addr);
self.search({
'address': addr
}, function (results, status) {
if (status === 'OK') {
addressPoint = results[0].geometry.location;
alert(addressPoint);
options = $.map(options, function () {
return results[0].geometry.location;
});
self.get('map').panTo(results[0].geometry.location);
alert(options);
return false;
}
});
}
});
}
};
}(jQuery));
Did you use a network sniffer to confirm it is only firing once? Because it looks like you are replacing each value in the list with a single value in the
$.mapcommand. Perhaps if you put the address points in a different array it would help: