.NET Core利用腾讯地图提供的接口逆解析,根据传进来的经纬度(第一个参数是纬度,第二个参数是经度)返回省市区街道的接口

 1.类文件(写在一个类文件即可)

namespace net5.Model.Model.acc
{
    public class GetMapDetailInput
    {
        public int status { get; set; }
        public string message { get; set; }
        public string request_id { get; set; }
        public Result result { get; set; }
        public string province { get; set; }
        public string city { get; set; }
        public string district { get; set; }
        public string street { get; set; }
    }
    public class Result
    {
        public AddressComponent address_component { get; set; }
    }

    public class AddressComponent
    {
        public string province { get; set; }
        public string city { get; set; }
        public string district { get; set; }
        public string street { get; set; }
        public string street_number { get; set; }
    }
}

 2.秘钥

  private static string key = "";//自己的秘钥
        private static string get_poi = "1";

 3.根据经纬度返回省市区街道

[HttpGet("getMapDetail")]
        public object GetGetMapDetail(string location)
        {
            HttpClient httpClient = new HttpClient();
            string url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + location + "&key=" + key + "&get_poi=" + get_poi;
            string result = httpClient.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
            var obj = JsonConvert.DeserializeObject<GetMapDetailInput>(result);
            string province = obj.result.address_component.province;
            string city = obj.result.address_component.city;
            string district = obj.result.address_component.district;
            string street = obj.result.address_component.street;
            string streetNumber = obj.result.address_component.street_number;
            return new
            {
                Province = province,
                City = city,
                District = district,
                Street = street,
                StreetNumber = streetNumber
            };
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值