Geocoder over the limit
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 finishedCount = 0;
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(12.713107, 78.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();
for (i = 0; i < citiesInTexas.length; i++) {
Geocode(citiesInTexas[i]);
}
}
var retryCounter = 0;
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
});
//reset counter
retryCounter = 0;
bounds.extend(marker.position);
} else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
//make sure we are not stuck in a loop
setTimeout(function() {
//retry
retryCounter++;
console.log(retryCounter);
Geocode(address);
}, 200);
} else {
alert("Geocode was not successful for the following reason:" + status);
}
});
}
function UpdateProgress() {
var progress = Math.round((finishedCount /...