将地理编码API超过查询限制 [英] Geocoding api over query limit

查看:101
本文介绍了将地理编码API超过查询限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器端使用地理编码API来翻译latlng中的地址。
即使:
- 服务器没有超过2500限制(在这一天只有几个请求)
- 它并没有同时执行很多请求一次一个请求)

I'm using the geocoding API on the server side to translate addresses in latlng. I faced a OVER_QUERY_LIMIT status even though : - the server didn't exceed the 2500 limitation (just a few request on this day) - it didn't do many requests simultaneously (just one single request at a time)

这怎么可能?第二天地理编码运行良好,但我担心我的应用程序长期运行正常。

how is that possible ? the next day the geocoding was working well but i'm concerned about my application working correctly in the long run.

预先致谢。

推荐答案

这是我过去处理这个问题的方法。我检查结果状态,如果我得到并超过了极限错误,我会在稍微延迟后重试。

This is how I have handled this issue in the past. I check the result status and if I get and over the limit error I try it again after a slight delay.

function Geocode(address) {
    geocoder.geocode({
        'address': address
    }, function(results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            var result = results[0].geometry.location;
            var marker = new google.maps.Marker({
                position: result,
                map: map
            });
        } else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {    
            setTimeout(function() {
                Geocode(address);
            }, 200);
        } else {
            alert("Geocode was not successful for the following reason:" 
                  + status);
        }
    });
}

更新:哎呦,偶然掩盖了服务器端的一部分。这是一个C#版本:

Update: whoops, accidentally glossed over the server side part. Here is a C# version:

public XElement GetGeocodingSearchResults(string address)
{
    var url = String.Format(
         "https://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false",
          Uri.EscapeDataString(address)); 

    var results = XElement.Load(url); 

    // Check the status
    var status = results.Element("status").Value;

    if(status == "OVER_QUERY_LIMIT")
    {
        Thread.Sleep(200);
        GetGeocodingSearchResults(address);
    }else if(status != "OK" && status != "ZERO_RESULTS")
    {
        // Whoops, something else was wrong with the request...     
    }

    return results;
}

这篇关于将地理编码API超过查询限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆