谷歌地图地理编码API V3使用wifi搜索确定,但通过数据连接响应OVER_QUERY_LIMIT

Umb*_*rto 2 android android-maps google-geocoding-api

我的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;
}
Run Code Online (Sandbox Code Playgroud)

响应管理:

    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();
    }
Run Code Online (Sandbox Code Playgroud)

小智 6

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

10*200ms重新查询的成功似乎与服务器端OVER_QUERY_LIMIT标志的到期有关,因为它(Google Maps API Web服务的使用限制)文件暗示,这表明收到此状态后,你应该在2秒后重新查询,看看你是否超过了你的日常使用量,或者你发送的请求太多了.

这不是通过wifi发生的,因为您的手机拥有自己的,或多或少的独特IP.