当前位置:首页 > Windows程序 > 正文

C#请求百度舆图API 盘问经纬度 开脱js

2024-03-31 Windows程序

public class BaiduPosition
{
public int status { get; set; }

public Result result { get; set; }
}

public class Result
{
public Location location { get; set; }
public int precise { get; set; }
public int confidence { get; set; }
public string level { get; set; }
}

public class Location
{
public decimal lng;
public decimal lat;
public Location(decimal x, decimal y)
{
lng = x;
lat = y;
}
}

public static class BaiduMap
{
public static Location GetSupplierLocation(string address)
{
address += "上海市" + address;
String url = "http://api.map.baidu.com/geocoder/v2/?address=" + address + "&output=json&ak=XBPX8dmIuAzluWeOtTAzsCECpkxkLudV";
var response = WebHelper.HttpWebRequest(url, string.Empty, Encoding.UTF8, false);
decimal lng = 0, lat = 0;

var position = Json.ToObject<BaiduPosition>(response);
if (position != null && position.status == 0 && position.result != null && position.result.location != null)
{
lng = position.result.location.lng;
lat = position.result.location.lat;
}

return new Location(lng, lat);
}
}

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/35858.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494590访问次数
  • 建站天数
  • 友情链接