public static string Output(string origin, string destination, string city) { string output = ""; var json = LinkAPI.RequestApi(origin, city, destination, city, "driving"); JObject jo = JObject.Parse(json); if (jo["result"] != null && jo["result"]["routes"] != null) { output = "时间:" + jo["result"]["routes"][0]["duration"].ToString() + " 距离:" + jo["result"]["routes"][0]["distance"].ToString(); } return(output); }
private void function() { if (dt != null) { for (int i = 0; i < dt.Rows.Count; ++i) { origin = dt.Rows[i][originHead].ToString() + txb_zone.Text.ToString(); destination = dt.Rows[i][destinationHead].ToString() + txb_zone.Text.ToString(); city = dt.Rows[i][cityHead].ToString() + txb_zone.Text.ToString(); string ori_tmp = origin; string des_tmp = destination; #region deal data try { var json = LinkAPI.RequestApi(origin, city, destination, city); JObject jo = JObject.Parse(json); while (jo["result"] != null && jo["result"]["routes"] == null) { origin = jo["result"]["origin"]["content"][0]["name"].ToString(); destination = jo["result"]["destionation"]["content"][0]["name"].ToString(); json = LinkAPI.RequestApi(origin, city, destination, city); jo = JObject.Parse(json); } duration = jo["result"]["routes"][0]["duration"].ToString(); distance = jo["result"]["routes"][0]["distance"].ToString(); if (this.IsHandleCreated) { this.BeginInvoke(updateText, "序号:" + i + " " + city + " " + ori_tmp + " " + des_tmp + " " + /*origin+" " + destination+*/ " 时间:" + duration + " 距离:" + distance); //Thread.Sleep(20); } } catch { undo_data_count++; if (this.IsHandleCreated) { this.BeginInvoke(updateText, "序号:" + i + " " + city + " " + ori_tmp + " " + des_tmp); } } #endregion } if (this.IsHandleCreated) { this.BeginInvoke(updateText, "数据处理结束"); } } }