谷歌地图API地理编码V3搜索OK带wifi,但响应OVER_QUERY_LIMIT与数据连接 [英] Google Maps Geocoding API V3 search ok with wifi but responses OVER_QUERY_LIMIT with data connection

查看:177
本文介绍了谷歌地图API地理编码V3搜索OK带wifi,但响应OVER_QUERY_LIMIT与数据连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的地址,谷歌地图搜索活动与谷歌地图地理编码API V3 。< BR> 我看到有些时候,即使我重复搜索多次的顺序,谷歌地图的反应是,当我用数据连接正在连接OVER_QUERY_LIMIT。
它也发生在应用程序的设备上安装后第一次搜索。
当我带wifi连接它完美。
这是我的code。
搜索方式:

 公共静态的JSONObject getAddressInfo(字符串sAddress){
    HTTPGET HTTPGET =新HTTPGET(http://maps.google.com/maps/api/geo$c$c/json?address=+ sAddress +&放大器;区=资讯科技及电讯,语言=资讯科技及电讯,传感器=假 );
    HttpClient的客户端=新DefaultHttpClient();
    HTT presponse响应;
    StringBuilder的StringBuilder的=新的StringBuilder();

    尝试 {
        响应= client.execute(HTTPGET);
        HttpEntity实体= response.getEntity();
        InputStream的流= entity.getContent();
        INT B:
        而((二= stream.read())!=  -  1){
            stringBuilder.append((char)的B);
        }
    }赶上(ClientProtocolException E){
    }赶上(IOException异常E){
    }

    的JSONObject的JSONObject =新的JSONObject();
    尝试 {
        的JSONObject =新的JSONObject(stringBuilder.toString());
        Log.d(谷歌地理编码响应,stringBuilder.toString());
    }赶上(JSONException E){
        e.printStackTrace();
    }
    返回的JSONObject;
}
 

响应管理:

 的JSONObject的JSONObject = Utils.getAddressInfo(Utils.strToUrl(inputName.getText()的toString()修剪()));
    尝试 {
        字符串sStatus = jsonObject.getString(状态);
        如果(sStatus.equals(OK)){
            LNG = ((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry").getJSONObject("location").getDouble("lng");
            土地增值税= ((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry").getJSONObject("location").getDouble("lat");
            bdlData.putDouble(土地增值税,LAT);
            bdlData.putDouble(LNG,LNG);
            bdlData.putFloat(dZoom,dZoom);
            message.setData(bdlData);
            mapHandler.sendMessage(消息);
        }否则,如果(sStatus.equals(ZERO_RESULTS)){
            runMsgOnUIThread(今夜risultato已找到。);
        }否则,如果(sStatus.equals(OVER_QUERY_LIMIT)){
            runMsgOnUIThread(Impossibile effettuare拉RICERCA人时代报Riprovare FRA qualche SECONDO。);
        }否则,如果(sStatus.equals(REQUEST_DENIED)){
            runMsgOnUIThread(Richiesta非accettata Riprovare。);
        }否则,如果(sStatus.equals(INVALID_REQUEST)){
            runMsgOnUIThread(Indirizzo非esistente。);
        }否则,如果(sStatus.equals(UNKNOWN_ERROR)){
            runMsgOnUIThread(Impossibile effettuare拉RICERCA人时代报Riprovare。);
        }
    }赶上(JSONException E){
        e.printStackTrace();
    }
 

解决方案

您的问题很可能驻留在您的移动运营商。运营商绝大多数使用了一种叫做NAT技术,重载和分配相同的外部IP到多个设备。如果运营商分配了一个非常大的数字设备的单一IP和其中一些使用类似的服务,每个人都会有一个问题,因为所有的请求都会出现来自同一个IP阻止。

您的成功与10 * 200毫秒重新查询,似乎与服务器端的OVER_QUERY_LIMIT标志的有效期进行连接,因为它是隐含在这(的使用限制谷歌地图API的Web服务)的文件,这表明在收到这个状态,你应该2secs后重新查询,看看是否超出了你的日常使用情况,或者你发送太多的请求。

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

My Google Maps activity searches for addresses with Google Maps Geocoding API V3.
I see that sometimes, even if I repeat the search multiple times in sequence, Google Maps response is OVER_QUERY_LIMIT when I'm connected with data connection.
It also happens on the first search after app's installation on a device.
When I'm connected with wifi it works perfectly.
Here's my code.
Search method:

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;
}

Response management:

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

解决方案

Your problem most probably resides in your mobile operator. The vast majority of operators use a technique called NAT overloading and assign the same external IP to a number of devices. If your operator assigns a very large number of devices to a single IP and a number of them uses similar services, everyone will have a problem, as all requests will appear to stem from the same IP.

Your success with the 10*200ms requeries seems to be connected with the expiration of the OVER_QUERY_LIMIT flag from the server-side, as it is implied in this(Usage Limits for Google Maps API Web Services) document, which suggests that upon receiving this status, you should requery after 2secs to see if you exceeded your daily usage or you sent too many requests.

This does not occur through wifi as your phone has its own, more-or-less unique IP.

这篇关于谷歌地图API地理编码V3搜索OK带wifi,但响应OVER_QUERY_LIMIT与数据连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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