【发布时间】:2016-04-29 06:52:40
【问题描述】:
我通过 Json 收到了 LatLang,但现在我想在 Postexecute 方法中的地图上显示这是我的代码
ServiceHandler serviceClient = new ServiceHandler();
Log.d("url: ", "> " + URL_ITEMS);
String json = serviceClient.makeServiceCall(URL_ITEMS, ServiceHandler.GET);
// print the json response in the log
Log.d("Get match fixture resps", "> " + json);
if (json != null) {
try {
Log.d("try", "in the try");
JSONObject jsonObj = new JSONObject(json);
Log.d("jsonObject", "new json Object");
// Getting JSON Array node
matchFixture = jsonObj.getJSONArray(TAG_FIXTURE);
Log.d("json aray", "user point array");
int len = matchFixture.length();
Log.d("len", "get array length");
for (int i = 0; i < matchFixture.length(); i++) {
JSONObject c = matchFixture.getJSONObject(i);
Double matchId = Double.parseDouble(c.getString(TAG_MATCHID));
Log.d("matchId", String.valueOf(matchId));
Double teamA = Double.valueOf(c.getString(TAG_TEAMA));
Log.d("teamA", String.valueOf(teamA));
// hashmap for single match
HashMap<String, String> matchFixture = new HashMap<String, String>();
// adding each child node to HashMap key => value
matchFixture.put(TAG_MATCHID, String.valueOf(matchId));
matchFixture.put(TAG_TEAMA, String.valueOf(teamA));
matchFixtureList.add(new LatLng(matchId, teamA));
}
} catch (JSONException e) {
Log.d("catch", "in the catch");
e.printStackTrace();
}
} else {
Log.e("JSON Data", "Didn't receive any data from server!");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
for (LatLng point:matchFixtureList){
mMap.addMarker(new MarkerOptions().position(point).title("chexk"));
}
// mMap.addMarker(new MarkerOptions().position(pakistan).title("Marker in pakistn"));
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.animateCamera(CameraUpdateFactory.zoomTo(16));
}
那么我如何在地图上显示标记,我在日志中收到所有纬度和纬度,但它在 logcatdfdfd 中显示空指针
【问题讨论】:
-
如果提供的纬度经度是硬编码的,你会收到错误吗?还是显示正常?
-
如果你的
matchFixtureList是一个全局变量,我认为你不需要改变任何东西。但最好遵循@ccsnoopy 的回答。 -
先生,我只想根据我通过 JSON 收到的 LatLang 显示标记
-
我认为您正在寻找类似 @987654321@ 的东西,希望对您有所帮助!
标签: android json google-maps