我通过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));
}
那么如何在地图上显示标记我在日志中收到所有lat和lang但在logcat中显示nullpointer dfdfd
答案 0 :(得分:1)
您在(我假设的)points = [
[2.9600000000000004, 6.3999999999999995],
[2.72, 4.8],
[2.48, 3.1999999999999997],
[2.2399999999999998, 1.5999999999999996],
[4.32, 6.3999999999999995],
[4.24, 4.8],
[4.16, 3.1999999999999997],
[4.08, 1.5999999999999996],
[5.68, 6.3999999999999995],
[5.759999999999999, 4.8],
[5.84, 3.1999999999999997],
[5.92, 1.5999999999999996],
[7.04, 6.3999999999999995],
[7.28, 4.8],
[7.5200000000000005, 3.1999999999999997],
[7.76, 1.5999999999999996],
[0, 0],
[2.0, 0.0],
[4.0, 0.0],
[6.0, 0.0],
[8.0, 0.0],
[10, 0],
[2, 8],
[3.2, 8.0],
[4.4, 8.0],
[5.6, 8.0],
[6.8, 8.0],
[8, 8],
[2, 8],
[1.6, 6.4],
[1.2, 4.8],
[0.7999999999999998, 3.1999999999999993],
[0.3999999999999999, 1.5999999999999996],
[0, 0],
[8, 8],
[8.4, 6.4],
[8.8, 4.8],
[9.2, 3.1999999999999993],
[9.6, 1.5999999999999996],
[10, 0]
]
方法中返回了null
。
尝试将doInBackground()
更改为:
doInBackground
答案 1 :(得分:0)
检查教程中的所有步骤。交叉检查你是否已经遵循了一切。 http://wptrafficanalyzer.in/blog/adding-marker-at-user-input-latitude-and-longitude-in-google-map-android-api-v2/
对Keystore部分施加更多压力。是否与您使用或其他
相同