Google Maps API V3 limits

I have been trying to get a google maps api query over the 10 query limit all morning with no luck. I have used this code here http://pastebin.com/X0icm1B8. I tried wrapping .each in a setTimeOut function at line 44 as well as trying it with the marker var but not luck. I found several results in google but haven’t been able to get any of them to work in my code. Any help would be great thanks so much in advance.

Errmmm. they’re called limits for a reason. Rather than trying to violate the Terms, have you looked into Solutions ??

Accually if you read a little further you can throttle your request, which is what I am trying to do.

Throttle requests

Applications should throttle requests to avoid exceeding usage limits, bearing in mind these apply to each client ID regardless of how many IP addresses the requests are sent from.

You can throttle requests by putting them through a queue that keeps track of when are requests sent. With a rate limit or 10 QPS (queries per second), on sending the 11th request your application should check the timestamp of the first request and wait until 1 second has passed. The same should be applied to daily limits.

Even if throttling is implemented correctly applications should watch out for responses with status code OVER_QUERY_LIMIT. If such response is received, use the pause-and-retry mechanism explained in the Usage limits exceeded section above to detect which limit has been exceeded.

Thanks, so you’re wanting to convert the example Python code into javascript?

url = "MAPS_API_WEBSERVICE_URL"
attempts = 0
success = False

while success != True and attempts < 3:
  raw_result = urllib.urlopen(url).read()
  attempts += 1
  # The GetStatus function parses the answer and returns the status code
  # This function is out of the scope of this example (you can use a SDK).
  status = GetStatus(raw_result)
  if status == "OVER_QUERY_LIMIT":
    time.sleep(2)
    # retry
    continue
  success = True

if attempts == 3:
  # send an alert as this means that the daily limit has been reached
  print "Daily limit has been reached"

Basically. This js script gets everything I need, but there are 15 address which exceeds the 10 limit. I have been trying to get a setTimeout function to it so that it delays the request of each address with a 1sec delay which will allow all 15 to be displayed and avoid the limit exceeding.

var map,
                bounds,
                geocoder,
                center;

            
            function addMarkerToMap(location, address){
            //var image = "assets/img/set_image.png"; // Replace set_image.png with image path
                
                var marker = new google.maps.Marker({
                        map: map,
                        position: location,
                        //icon: image
                });
                bounds.extend(location);
                map.fitBounds(bounds);
                var infoWindow = new google.maps.InfoWindow({
                    content: address
                });
                google.maps.event.addListener(marker, 'click', function() {
                    infoWindow.open(map, marker);
                });
            }
            
            function initialize() {
              var mapOptions = {
                scrollwheel: false,
                mapTypeControl: false,
                streetViewControl: false,
                zoom: 10,
                center: new google.maps.LatLng(37.09024, -95.712891),
                mapTypeId: google.maps.MapTypeId.ROADMAP
              };
              map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
                geocoder = new google.maps.Geocoder();
                bounds = new google.maps.LatLngBounds();
            }

            initialize();
            
            $('address', parent.window.document).each(function() {
                
                var $address = $(this);
                // TRYED WRAPPING setTimeOut FUNCTION HERE BUT NO LUCK
                geocoder.geocode({ address: $address.html() }, function(
                    results,
                    status
                    )  {
                    if(status == google.maps.GeocoderStatus.OK) addMarkerToMap(
                         results[0].geometry.location, $address.html());
                }); // ENDED FUNCTION HERE }, 2000); BUT NO LUCK
                
                console.log($address.length);
            }); 

            google.maps.event.addDomListener(map, 'idle', function() {
            center = map.getCenter();
        });

        $(window).resize(function() {
            map.setCenter(center);
            
        });

Here is how I figured it out. With help from this post setinterval or settimeout for google map v3 I created a new array for the addresses with a function. Then place the existing address query inside a function with some changes. This allowed me to instead of setTimeout use setInvterval. Worked perfect. Below is the code if anyone else needs it.


var map,
        bounds,
        geocoder,
        addresses = new Array(),
        center;

    function addMarkerToMap(location, address){
        //var image = "assets/img/set_image.png"; // Replace set_image.png with image path 
        var marker = new google.maps.Marker({
            map: map,
            position: location,
            //icon: image
        });

        bounds.extend(location);
        map.fitBounds(bounds);

        var infoWindow = new google.maps.InfoWindow({
            content: address
        });

        google.maps.event.addListener(marker, 'click', function() {
            infoWindow.open(map, marker);
        });
    }

    function initialize() {
        var mapOptions = {
            scrollwheel: false,
            mapTypeControl: false,
            streetViewControl: false,
            zoom: 10,
            center: new google.maps.LatLng(37.09024, -95.712891),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
            geocoder = new google.maps.Geocoder();
            bounds = new google.maps.LatLngBounds();
        }

        initialize();

    // Created the array 
    function getAddresses () {
        $('address',parent.window.document).each(function () {
            addresses.push($(this).html());
        });
    }

    getAddresses();
    theInterval = setInterval('codeAddress()', 100); // Set the Interval

    // New Function for address
    function codeAddress() {     
        if (addresses.length == 0) {
            clearInterval(theInterval);
        }

        var address = addresses.pop();

        geocoder.geocode({ address: address }, function( results, status ) {
            if(status == google.maps.GeocoderStatus.OK) addMarkerToMap(
                results[0].geometry.location,  address );
        });
    }

    google.maps.event.addDomListener(map, 'idle', function() {
        center = map.getCenter();
    });

    $(window).resize(function() {
        map.setCenter(center);
    });