2 sinat 34881157 sinat_34881157 于 2016.09.23 17:19 提问

百度地图Api中如何将经纬度转成地址 3C

求核心的转换代码:
把106.294429,29.164067转换成重庆市重庆时渝中区

2个回答

showbo
showbo   Ds   Rxr 2016.09.23 18:01

js的还是什么的?

js下面的,注意ak替换成你自己的

   <script>
        function renderReverse(rst) {
            if (rst.status == 0) {
               alert(rst.result.formatted_address)
            }
            else alert(rst.status+'\n解码出错')
        }
    </script>
    <script src="http://api.map.baidu.com/geocoder/v2/?ak=1offaO5cablVaW8XYuwtsrVb&callback=renderReverse&location=29.164067,106.294429&output=json&pois=1"></script>

API文档:http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding#.E9.80.86.E5.9C.B0.E7.90.86.E7.BC.96.E7.A0.81.E6.9C.8D.E5.8A.A1

caozhy
caozhy 正解。
大约一年之前 回复
zhanghaili123456789
zhanghaili123456789   2016.09.28 10:52

private void btnRegeo_Click(object sender, EventArgs e)
{
string location = txtLon.Text + "," + txtLat.Text;
string str = “”“请求地址
txtPosition.Text = str;

        PositionInfo user = (PositionInfo)JsonConvert.DeserializeObject(str, typeof(PositionInfo));
        txtPosition.Text = user.regeocode.formatted_address;
        txtProvince.Text = user.regeocode.addressComponent.province;
        txtCity.Text = user.regeocode.addressComponent.city;
    }


    public class PositionInfo
    {
        public string status;
        public string info;
        public string infocode;
        public regeocode regeocode;
    }
    public class regeocode
    {
        public string formatted_address;
        public addressComponent addressComponent;
    }
    public class addressComponent
    {
        public string country;
        public string province;
        public string city;
        public string citycode;
        public string district;
        public string adcode;
        public string township;
        public string towncode;
        public building building;
    }
    public class building
    {
        public streetNumber streetNumber;
    }
    public class streetNumber
    {
        public string street;
        public string number;
        public string location;
        public string direction;
        public string distance;
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!