我的 Google Maps 活动使用Google Maps Geocoding API V3搜索地址。
我看到有时,即使我按顺序重复搜索多次,当我连接到数据连接时,谷歌地图的响应也是 OVER_QUERY_LIMIT 。
它也发生在设备上安装应用程序后的第一次搜索中。
当我连接到 wifi 时,它工作得很好。
这是我的代码。
搜索方法:
public static JSONObject getAddressInfo(String sAddress) {
HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?address=" + sAddress + "®ion=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();
}