コード例 #1
0
  public String getInfo() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("language", "zh-CN");
    map.put("sensor", "false");
    map.put("latlng", getLatlng());

    String url = URLHelper.GOOGLELOCATION;

    String jsonData = null;
    try {
      jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    } catch (WeiboException e) {
      AppLogger.e(e.getMessage());
    }

    try {
      JSONObject jsonObject = new JSONObject(jsonData);
      JSONArray results = jsonObject.optJSONArray("results");
      JSONObject jsonObject1 = results.getJSONObject(0);
      String formatAddress = jsonObject1.optString("formatted_address");
      int index = formatAddress.indexOf(" ");
      if (index > 0) {
        String location = formatAddress.substring(0, index);
        return location;
      } else {
        return formatAddress;
      }
    } catch (JSONException e) {
      AppLogger.e(e.getMessage());
    }

    return "";
  }
 @Override
 protected void onCancelled(UserBean userBean) {
   super.onCancelled(userBean);
   if (e != null) {
     Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
   }
 }