【问题标题】:Google Maps Geocoding API V3 search ok with wifi but responses OVER_QUERY_LIMIT with data connectionGoogle Maps Geocoding API V3 使用 wifi 搜索正常,但使用数据连接响应 OVER_QUERY_LIMIT
【发布时间】:2013-05-27 09:58:01
【问题描述】:

我的 Google 地图活动搜索带有Google Maps Geocoding API V3 的地址。
我看到有时,即使我按顺序重复搜索多次,当我连接到数据连接时,Google 地图的响应也是 OVER_QUERY_LIMIT。
在设备上安装应用后的第一次搜索时也会发生这种情况。
当我与 wifi 连接时,它可以完美运行。
这是我的代码。
搜索方式:

public static JSONObject getAddressInfo(String sAddress) {
    HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?address=" + sAddress + "&region=it&language=it&sensor=false");
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    try {
        response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        int b;
        while ((b = stream.read()) != -1) {
            stringBuilder.append((char) b);
        }
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }

    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject = new JSONObject(stringBuilder.toString());
        Log.d("Google Geocoding Response", stringBuilder.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return jsonObject;
}

响应管理:

    JSONObject jsonObject = Utils.getAddressInfo(Utils.strToUrl(inputName.getText().toString().trim()));
    try {
        String sStatus = jsonObject.getString("status");
        if (sStatus.equals("OK")) {
            lng = ((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry").getJSONObject("location").getDouble("lng");
            lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry").getJSONObject("location").getDouble("lat");                     
            bdlData.putDouble("lat", lat);
            bdlData.putDouble("lng", lng);
            bdlData.putFloat("dZoom", dZoom);
            message.setData(bdlData);
            mapHandler.sendMessage(message);
        } else if (sStatus.equals("ZERO_RESULTS")) {
            runMsgOnUIThread("Nessun risultato trovato.");
        } else if (sStatus.equals("OVER_QUERY_LIMIT")) {
            runMsgOnUIThread("Impossibile effettuare la ricerca al momento. Riprovare fra qualche secondo.");
        } else if (sStatus.equals("REQUEST_DENIED")) {
            runMsgOnUIThread("Richiesta non accettata. Riprovare.");
        } else if (sStatus.equals("INVALID_REQUEST")) {
            runMsgOnUIThread("Indirizzo non esistente.");
        } else if (sStatus.equals("UNKNOWN_ERROR")) {
            runMsgOnUIThread("Impossibile effettuare la ricerca al momento. Riprovare.");                   
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

【问题讨论】:

    标签: android android-maps google-geocoding-api


    【解决方案1】:

    您的问题很可能在于您的移动运营商。绝大多数运营商使用一种称为 NAT 过载的技术,并将相同的外部 IP 分配给多个设备。如果您的运营商将大量设备分配给单个 IP,并且其中许多设备使用类似的服务,那么每个人都会遇到问题,因为所有请求似乎都来自同一个 IP。

    您在 10*200ms 请求上的成功似乎与服务器端的 OVER_QUERY_LIMIT 标志的到期有关,正如此 (Usage Limits for Google Maps API Web Services) 文档中所暗示的那样,这表明在收到此状态后,您应该在 2 秒后重新查询,看看您是否超出了日常使用量或发送了太多请求。

    这不会通过 wifi 发生,因为您的手机有自己的或多或少唯一的 IP。

    【讨论】:

    • 感谢您的支持!我以为可能是这样……奇怪的是,使用相同的连接:a)Google Maps 应用程序运行良好; b) Android Geocoder 类运行良好(由于其他问题,我实际上并没有使用它)......现在我该怎么办?
    • Google Maps 应用程序肯定会使用 Google 的客户端 ID 来处理他们的请求,因此他们可能对应用程序没有限制。如果 Geocoder 类也能正常工作,那么它要么也在使用该客户端 ID,要么更有效地限制和缓存请求。
    • 我明白了。那么你建议我如何解决这个问题?有人告诉我不要使用 Geocoder 类:stackoverflow.com/a/16656050/1769013
    • aBrav 请回答我的最后一个问题。非常感谢。
    • 除了上述文章中的建议外,我能给您的建议不多。您可以尝试优化您的请求处理、限制它、使用 Geocoder 类并克服其限制,或者按照优先顺序获得 Maps API for Business 许可证。单独使用缓存(如果按照说明使用)应该会提高您的成功率,但不会超过您的使用配额。
    【解决方案2】:

    我找到了一种经常(并非总是)解决问题的解决方法:如果我得到 OVER_QUERY_LIMIT,则每 200 毫秒重新查询一次 Google,最多 10 次。

    【讨论】:

      猜你喜欢
      • 2015-12-16
      • 2013-11-17
      • 1970-01-01
      • 2018-02-27
      • 2015-06-10
      • 2017-08-17
      • 2013-12-27
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多