码迷,mamicode.com
首页 > Windows程序 > 详细

C#请求百度地图API 查询经纬度 摆脱js

时间:2017-12-15 15:05:52      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:查询   add   地图api   enc   help   请求   conf   ott   bre   

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);
}
}

C#请求百度地图API 查询经纬度 摆脱js

标签:查询   add   地图api   enc   help   请求   conf   ott   bre   

原文地址:http://www.cnblogs.com/morpheusliu/p/8042769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!