我在嘗試下載並顯示折線。正在下載折線信息
我有這樣的任務異步設置:
private class taskGetPolyline extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog;
StringBuilder urlString;
String response;
int i;
private taskGetPolyline(int i) {
this.i = i; //passes in id of closest marker
}
@Override protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(ContentActivity.this);
dialog.setTitle(getResources().getText(
R.string.progress_download_route));
dialog.setMessage(getResources().getText(
R.string.progress_please_wait)); dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false); dialog.show();
urlString = new StringBuilder(); urlString
.append("http://maps.googleapis.com/maps/api/directions/json");
urlString.append("?origin=");
urlString.append(LOCATION_CURRENT.getLatitude()); urlString.append(",");
urlString.append(LOCATION_CURRENT.getLongitude());
urlString.append("&destination=");
urlString.append(arrayLocation[i].latitude);
urlString.append(",");
urlString.append(arrayLocation[i].longitude);
urlString.append("&sensor=false");
Log.i("DEBUG","link: " + urlString.toString());
}
@Override
protected Void doInBackground(Void... params) {
try {
HttpClient Client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urlString.toString());
ResponseHandler<String> responseHandler = new BasicResponseHandler();
response = Client.execute(httpGet, responseHandler);
Log.i("DEBUG", "response = " + response);
} catch (Exception e) {
Log.i("Exception", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void result) {
JSONObject jsonResponse;
try {
jsonResponse = new JSONObject(response);
JSONObject jsonOverviewPolylines = jsonResponse
.getJSONObject("overview_polyline");
PolylineOptions polylineOptions = new PolylineOptions()
.addAll(decodePolyLine(jsonOverviewPolylines.toString()));
currentPolyline = map.addPolyline(polylineOptions);
} catch (JSONException e) {
e.printStackTrace();
}
dialog.dismiss();
}
}
但是當我運行這段代碼我得到logcat的警告:
10-31 14:48:43.744: W/System.err(10724): org.json.JSONException: No value for overview_polyline
日誌裏顯示整個鏈接,這很好。這裏的例子:不顯示,直到在日誌中結束 http://maps.googleapis.com/maps/api/directions/json?origin=46.14928015,16.00907806&destination=45.831534,16.02944&sensor=false
響應:
10-31 14:55:35.744: I/DEBUG(11671): response = {
10-31 14:55:35.744: I/DEBUG(11671): "routes" : [
10-31 14:55:35.744: I/DEBUG(11671): {
10-31 14:55:35.744: I/DEBUG(11671): "bounds" : {
10-31 14:55:35.744: I/DEBUG(11671): "northeast" : {
10-31 14:55:35.744: I/DEBUG(11671): "lat" : 46.1724292,
10-31 14:55:35.744: I/DEBUG(11671): "lng" : 16.0385437
10-31 14:55:35.744: I/DEBUG(11671): },
10-31 14:55:35.744: I/DEBUG(11671): "southwest" : {
10-31 14:55:35.744: I/DEBUG(11671): "lat" : 45.7876853,
10-31 14:55:35.744: I/DEBUG(11671): "lng" : 15.8190462
10-31 14:55:35.744: I/DEBUG(11671): }
10-31 14:55:35.744: I/DEBUG(11671): },
...
10-31 14:55:35.744: I/DEBUG(11671): "html_instructions" : "Slight \u003cb\u003eright\u003c/b\u003e toward \u003cb\u003eVelika Petrovagorska\u003c/b\u003e",
10-31 14:55:35.744: I/DEBUG(11671): "maneuver" : "turn-slight-right",
10-31 14:55:35.744: I/DEBUG(11671): "polyline" : {
10-31 14:55:35.744: I/DEBUG(11671): "points" : "yxtxGixu`[email protected]?QFOJUL[[email protected][email protected]@@[email protected][email protected]_AI{@IiAEYEWCQCY?Y?]@[email protected]"
10-31 14:55:35.744: I/DEBUG(11671): },
10-31 14:55:35.744: I/DEBUG(11671): "start_location" : {
10-31 14:55:35.744: I/DEBUG(11671): "lat" : 46.1506939,
10-31 14:55:35.744: I/DEBUG(11671): "lng" : 16.0091667
10-31 14:55:35.744: I/DEBUG(11671): },
10-31 14:55:35.744: I/DEBUG(11671): "travel_mode" : "DRIVING"
10-31 14:55:35.744: I/DEBUG(11671): },
10-31 14:55:35.744: I/DEBUG(11671): {
10-31 14:55:35.744: I/DEBUG(11671): "distance" : {
10-31 14:55:35.744: I/DEBUG(11671): "text" :
我失去了這部分從響應:
"overview_polyline" : {
"points" : "iptxGcxu`[email protected]@[email protected]@[email protected][email protected]}[email protected]}@[email protected]@[email protected]}[email protected]@}EUkC^[email protected]@[email protected]@uCWuFfAmEfB}[email protected]@[email protected]}[email protected]@`[email protected]@[email protected]@jNmAlDoBbFO`[email protected]|@xC|B|IjBdBjAbEjBxAxAW`BOvB|BvDhEpHlC|[email protected]@[email protected]@[email protected]@_AzAbApEhAlC`AiB`AoAvC^[email protected]}[email protected]~BfB][email protected][email protected]\\[email protected][email protected]\\`[email protected]@lGAzMtA`IlGdHzJtFlF`B|[email protected]@[email protected][email protected]|@hCQbF`[email protected][[email protected]@`[email protected]@tC?tCGvA^[email protected]|[email protected]{[email protected]@[email protected]}M~JuD~VwGtQ{[email protected][email protected]@nQbAnK[[email protected]`@[email protected][email protected][email protected]`@[email protected]@~In\\rFjP|GfMzHvJzIjH|[email protected]^|I`EzFxCrMhJjSnSbHhIvSvTtGxG|MzLjQlLzUzK`KfD`[email protected]@pNxT|[email protected]`@[email protected]|Q_B|[email protected]~[oD|WmHjWuL|[[email protected]@[email protected]{[email protected]{JlSaIdFwCvDcDbCwB|[email protected]@fAoABuAwAmAiCeJ}SyJwUaJiWuFwVwC}[email protected][email protected]@[email protected]}@`Bc_ApGkdB~DodAtA}[email protected]}[email protected]@y^[email protected]@[email protected][email protected][email protected]@U|@zCeB|[email protected]`@kOfL}Y`[email protected]{I{[email protected][email protected][email protected]@[email protected]|[email protected]~M{@[email protected]@}[email protected]"
},
"summary" : "E59",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
任何人有任何想法,爲什麼我可以不會得到全部答覆,然後只解析「overview_polyline」標籤?
不知道如果你能相信什麼是logcat的diplayed,因爲那隻能說明數據的4096b和你的JSON響應是巨大的 – 2014-10-31 14:13:34