2

私の 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();
    }
4

2 に答える 2

6

あなたの問題は、おそらく携帯電話会社にあります。大部分の通信事業者は、NAT オーバーロードと呼ばれる手法を使用して、同じ外部 IP を複数のデバイスに割り当てています。オペレーターが非常に多数のデバイスを 1 つの IP に割り当て、それらの多くが同様のサービスを使用している場合、すべての要求が同じ IP から発生しているように見えるため、すべての人に問題が発生します。

10*200 ミリ秒の再クエリで成功したことは、サーバー側からの OVER_QUERY_LIMIT フラグの有効期限に関連しているようです。これは、この ( Google Maps API Web サービスの使用制限) ドキュメントで暗示されているため、このステータスを受け取ると、 、2 秒後に再クエリして、1 日の使用量を超えていないか、送信したリクエストが多すぎないかを確認する必要があります。

お使いの携帯電話には独自の多かれ少なかれ一意の IP があるため、これは Wi-Fi では発生しません。

于 2013-06-14T13:17:58.620 に答える
0

多くの場合 (常にではありません)、問題を解決する回避策を見つけました: OVER_QUERY_LIMIT を取得した場合、200 ミリ秒ごとに最大 10 回まで Google に再クエリを実行します。

于 2013-06-12T07:24:07.533 に答える