android - 地理位置Json数据不显示
问题描述
我想我在尝试检索地理位置数据的地方写错了代码:添加了所有相关的 api 密钥并启用了相关的 api...
private class GetCoordinates extends AsyncTask<String, Void, String>
{
ProgressDialog dialog = new ProgressDialog(AroundMeMapsActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.setMessage("Please wait...");
dialog.setCanceledOnTouchOutside(true);
dialog.show();
}
@Override
protected String doInBackground(String... strings) {
String response;
try {
Toast.makeText(AroundMeMapsActivity.this, "!!!!", Toast.LENGTH_SHORT).show();
String address = strings[0];
HttpDataHandler http = new HttpDataHandler();
//String url = String.format("https://maps.googleapis.com/maps/api/geocode/json?adress=%s", address);
String url = String.format("https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=AIzaSyAzSgqQEZS1K1fowxhUnwxl4hMsKMsLlN4", address);
response = http.getHTTPData(url);
return response;
} catch (Exception ex) {
}
return null;
}
@Override
protected void onPostExecute(String s) {
try {
Toast.makeText(AroundMeMapsActivity.this, "????", Toast.LENGTH_SHORT).show();
JSONObject jsonObject=new JSONObject(s);
String lat=((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry")
.getJSONObject("location").get("lat").toString();
String lng=((JSONArray)jsonObject.get("results")).getJSONObject(0).getJSONObject("geometry")
.getJSONObject("location").get("lng").toString();
answer_location.setText(String.format("Coordinates: %s / %s",lat,lng));
if(dialog.isShowing())
dialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}
}
我应该得到纬度和经度坐标,但它没有显示......
你能帮忙看看为什么吗?
解决方案
推荐阅读
- python - Anaconda 安装问题
- python - 简单的包导入导致除以零警告
- pandas - 如何将大十进制数据从数据框保存到csv文件
- javascript - 如何重新渲染组件?反应原生
- node.js - nodejs mongodb 根据单个值检查范围
- laravel-livewire - 如何生成访问错误和错误消息,将用户留在页面上?
- matrix - 如何在 rust 中实现简单的 N 维向量?
- javascript - React.Fragment 组件未在其他组件中呈现
- html - 当我悬停时,如何保持其他块静止而不在 CSS 中移动?
- python - asyncio 挂在 SSL 握手上