简体   繁体   中英

Google geocoder limits

Is there a way of sending multiple addresses to through one geocode request:

geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        addMarker(results[0].geometry.location); 
        var the_string = generate_string(elements, a, address);

        infowindow[a] = new google.maps.InfoWindow({
            content: the_string
        });     

        google.maps.event.addListener(markersArray[a], "click", function() {
            infowindow[a].open(map, markersArray[a]);
        });
    } else {
        alert("Geocode was not successful for the following reason: " + status);
    }
});       

where address contains an array of addresses. Reason is I am coming across "OVER_QUERY_LIMIT" addressed here OVER_QUERY_LIMIT while using google maps and here Google Map Javascript API v3 - OVER_QUERY_LIMIT Error

I was wondering if i should start using the server side version of the client or continue with the javascript api and get help with sending an array of addresses through the geocoder call?

In your opinion or experience, if i have an application that you can type endless amounts of addresses into fields and then press a "plot to map" button, how would you go about doing this in terms of api calls, geocoding etc?

EDIT:////////////////////////

I'm now using this code:

class geocoder{
    static private $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=";

    static public function getLocation($address){
        $url = self::$url.urlencode($address);

        $resp_json = self::curl_file_get_contents($url);
        $resp = json_decode($resp_json, true);

        if($resp['status']='OK'){
            return $resp['results'][0]['geometry']['location'];
        }else{
            return false;
        }
    }

    static private function curl_file_get_contents($URL){
        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $URL);
        $contents = curl_exec($c);
        curl_close($c);

        if ($contents) return $contents;
            else return FALSE;
    }
}      

and calling it like so:

$address = urlencode($field_set["value"]);
$loc = geocoder::getLocation($address);

in a loop of every address being placed in (in this case 20 times).

It only places 10 markers on the map regardless of the loop correctly having 2 different lngs and lats.

It returns null for the last 10 lat lngs :s

EDIT:///////////////////////////

I have placed a sleep in the loop that calls this:

$loc = geocoder::getLocation($address);

every 8th geocoding, it pauses for a second then continues.. this seems to allow all geocoder locations to be rendered correctly... but it seems like a fluff.

Any ideas?

使用地址解析进行编码的最佳方法是在服务器上存储经度和纬度值,因此您不必在每次脚本运行时都发送一堆地址解析请求

No, the address have to be an address as specified in the documentation .

The geocoder will return an array of results, but you can't input an array of addresses to geocode/reverse-geocode, isn't too logic anyway and people would use it to exploit the limits.

You shouldn't worry too much on the query_limit, because it's per IP/day as long as it's javascript api and no backend. So if you have multiple users using this feature the limit is set to them individually and it doesn't sum up.

If you are going over the limit by a lot because you have a local environment, then you might need to hire the google maps for business services that have up to 100k requests daily I think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM