Geocoder over the limit
by bryan_weaver
HTML
<script src="http://maps.google.com/maps/api/js?sensor=false&.js"></script>
<div id="map"></div>
<p id="progress"></p>
CSS
#map{
width: 450px;
height: 400px;
}
JavaScript
var geocoder, map;
var bounds;
var citiesInTexas = ["Abbott TX", " Abernathy TX", " Abilene TX", " Ace TX", " Ackerly TX", " Addison TX", " Adkins TX", " Adrian TX", " Afton TX", " Agua Dulce TX", " Aiken TX", " Alamo TX", " Alanreed TX", " Alba TX", " Albany TX", " Aledo TX", " Alice TX", " Alief TX", " Allen TX", " Alleyton TX", " Allison TX", " Alpine TX", " Altair TX", " Alto TX"];
function initialize() {
var centerPosition = new google.maps.LatLng(34.713107, -101.42984);
var options = {
zoom: 6,
center: centerPosition,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map($('#map')[0], options);
bounds = new google.maps.LatLngBounds();
geocoder = new google.maps.Geocoder();
setBatchMarkers(citiesInTexas, 0, 0);
}
//batch count function
var finishedCount = 0;
var _count1AtLastPause = 0;
var _count2AtLastPause = 0;
function setBatchMarkers(items, i, batchCounter) {
for (; i < items.length; i++) {
if ((batchCounter + finishedCount) - (_count1AtLastPause + _count2AtLastPause) >= 4) {
_count1AtLastPause = batchCounter;
_count2AtLastPause = finishedCount;
return setTimeout(function() {
setBatchMarkers(items, i, batchCounter);
}, 2050);
} //end if
Geocode(items[i]);
batchCounter++;
}
}
function Geocode(address) {
geocoder.geocode({
'address': address
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
//update finished count so we know which markers are done.
finishedCount++;
UpdateProgress();
var result = results[0].geometry.location;
var marker = new google.maps.Marker({
position: result,
map: map
});
bounds.extend(marker.position);
} else {
alert("Geocode was not successful for the following...