开发者

Google Maps V3 API - Over Query Limit, but just 1 request

I recently began getting an Over Query Limit status response from the Google Map API when I send a single geocoding request. I'm really confused why this is happening? I definitely did not come anywhere close to reaching the 2,500 daily req开发者_如何学运维uest limit.

Also, if I just simply post my request (http://maps.googleapis.com/maps/api/geocode/json?address=1125+First+Avenue,New +York,NY&sensor=false) into a browser it works just fine and I get the proper response.

If anyone has any thoughts I'd appreciate it.


It seems like the reason this is happening is because I have the request as part of my php code, as such it's using my hosting providers (rackspace) ips for the request and they have reached their limit for the day based on what other people are doing.

The solution for avoiding this is to have the request sent by the client side using javascript so it's processed by the users browser and whatever ip they're currently using.

Hopefully the solution can help someone else.


When you are sending request from php the request will sent from you server IP and the google allows limited request for single ip, so it's better to send request from user's IP. You can do it by using below JavaScript function.

function display_map(address_str,business_name,phone_number,google_local_pages){

var address = address_str;

// Create a new Geocoder
var geocoder = new google.maps.Geocoder();

// Locate the address using the Geocoder.
    geocoder.geocode( { "address": address }, function(results, status) {

      // If the Geocoding was successful
      if (status == google.maps.GeocoderStatus.OK) {

          var latlang = results[0].geometry.location;
    //      alert(latlang);

        // Create a Google Map at the latitude/longitude returned by the Geocoder.
        var myOptions = {
          zoom: 16,
          center: results[0].geometry.location,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map"), myOptions);

        // Add a marker at the address.
        var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
        });

     //   var data = "<div id='top'><span>"+business_name+"</span><a href='"+google_local_pages+"'>More Info</a><div id='address'>"+address_str+"</div></div>";

        var infowindow = new google.maps.InfoWindow({
        content: "<div id='top' style='height:175px;width:200px;'><span id='bname' style='font-size: 1.3em;font-weight:bold;'>"+business_name+':'+"</span><a style='text-decoration: none;' target='_blank' href='"+google_local_pages+"'>More Info</a><hr/><div id='address' style='font-size: 1em;font-weight:normal;align:left'>"+address_str+"</div><hr/><div id='lower'><a style='text-decoration: none;' target='blank' href='http://maps.google.com/maps?saddr=&daddr="+address_str+"'"+">Directions</a>&emsp;<a style='text-decoration: none;' href='javascript:void(0);' onclick='showform();'>Search Nearby</a><div style='display:none;' id='hiddenForm'><hr><span style='font-size: 1em;font-weight:bold;'>Search Nearby:</span><form action='http://maps.google.com/maps' method='get' target='_blank'><input type='text' name='q' id='q' value='' size='12' /><input type='submit' value='GO'/>&emsp;<span phv='&quot;%1$s&quot;' style='font-size: 0.7em;font-weight: small;'>e.g.,&ldquo;pizza&ldquo;</span><input type='hidden' name='near' value='"+address_str+"'/></form></div></div>"
        });

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

      } else {
        try {
          console.error("Geocode was not successful for the following reason: " + status);
        } catch(e) {}
      }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜