调用高德地图接口

//1需要先请求接口

WebClient client = new WebClient();

//2把接口转换成byte数据

Byte[] byteTest = client.DownloadData("https://restapi.amap.com/v3/geocode/geo?address=" + 地址+ "&output=JSON&key=你申请的key");

//3转换成字符串
string data = Encoding.UTF8.GetString(byteTest);

//4反序列化
JObject obj = (JObject)JsonConvert.DeserializeObject(data);

//4经纬度

string a1 = obj["geocodes"][0]["location"].ToString();

//计算两经纬度之间的距离

Byte[] byteTest3 = client.DownloadData("https://restapi.amap.com/v3/direction/driving?origin= " + 经纬度1+ " &destination=" + 经纬度2+ "&output=JSON&key=你申请的key");

string data3 = Encoding.UTF8.GetString(byteTest3);
JObject obj3 = (JObject)JsonConvert.DeserializeObject(data3);
int a = ConvertHelper.GetInteger(obj3["route"]["paths"][0]["distance"]);

 

posted @ 2024-03-12 11:43  過朢  阅读(167)  评论(0)    收藏  举报