-1

small summary. Since geocoding doesn't allow a lot of simultaneous requests and I have to display more then 11 markers on my googlemap I figured I would use some sort of interval to bypass the simultaneous request limit.
I figured here I would use the setInterval function from javascript.

This is my code

 function timeHackGeocode(location, name, contract, vestigingID)
    {
      setInterval(codeAddress(location, name, contract, vestigingID), 1000);
    }

  function collectingData() {
        @foreach (var item in Model) {
        @:timeHackGeocode("@item.StraatVestiging" + " " + "@item.nr" + "," + "@item.location","@item.name","@item.Contract", "@item.id");
         }        
      }


 function codeAddress(location, name, contract, vestigingID) {
        var address = location;
        var image;
        var zoomlevel; 
        geocoder.geocode({ 'address': address }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                     var infoboxPos = results[0].geometry.location;
                     var image = new google.maps.MarkerImage(returnImage(contract),
                      // This marker is 20 pixels wide by 32 pixels tall.
                      new google.maps.Size(30, 42),
                      // The origin for this image is 0,0.
                      new google.maps.Point(40,45),
                      // The anchor for this image is the base of the flagpole at 0,32.
                      new google.maps.Point(0, 32));

                     var marker = createMarkers(results[0].geometry.location, contract)

                         google.maps.event.addListener(marker, 'mouseover', function() { 
                         infobox.open(map, marker);
                         infobox.setOptions(infoboxOptions(boxText(name, contract, vestigingID), infoboxPos));

                     });
            } else {
              // alert("Geocode was not successful for the following reason: " + status);
            }   
        });        
    }

Unfortunately this does not seem to work and I tried all kinds of different setups. https://developer.mozilla.org/en/DOM/window.setInterval

Does anyone have an idea what is going on?

ps. I will change this hack in the future by already having the latitude and longitude but for now I wish to get this to work.

Suggestions much appreciated.

Shinji
  • 85
  • 1
  • 11

2 Answers2

0

If you need to pass an argument to your callback function, but need it to work in Internet Explorer, which doesn't support sending additional parameters with setInterval(), use an anonymous function to call your callback.

var time =setInterval(function(){ codeAddress(location, name, contract, vestigingID); },1000);
Pranav
  • 8,563
  • 4
  • 26
  • 42
0

Getting round the rate limit is possible. See Google Map V3 : Only some markers are displayed which is exactly the same issue.

This is the relevant part of that answer:

You need to slow the requests down. As you submit more requests, you will probably have to slow them down more to satisfy the geocoder. I've made a Version 3 example (from a noted Version 2 example) at http://acleach.me.uk/gmaps/v3/plotaddresses.htm — you can see it starts out with a 100ms delay between requests, but needs to slow down to around 150ms after twenty iterations.

Community
  • 1
  • 1
Andrew Leach
  • 12,945
  • 1
  • 40
  • 47