zoukankan      html  css  js  c++  java
  • 百度地图

    网上找了半天都没有找到,找到的都是一些不能用的

    这个是有获取到城市名称,但是他获取的cityCode不是那种国家规范的那种编码,也可以用啦,到时候还要封装一大堆的东西,太麻烦了

    http://api.map.baidu.com/geocoder?location=24.900957,118.601253&output=json&key=你的AK

    原博客:https://blog.csdn.net/wy_blog/article/details/80969599

    网上找到大神自己封装的方法,就很方便了,上面已经贴出原地址,我的就只需要城市编码,我把路径后面的“&pois=1”去掉了。

         var geolocation = new BMap.Geolocation(); //创建geolocation实例,返回用户当前的位置
            // 开启SDK辅助定位
            geolocation.enableSDKLocation();
            geolocation.getCurrentPosition(function(r){ //返回用户当前位置。当定位成功时,回调函数的参数为GeolocationResult对象,否则为null
                if(this.getStatus() == BMAP_STATUS_SUCCESS){
                    sessionStorage.setItem("SDKLng",r.point.lng);
                    sessionStorage.setItem("SDKLat",r.point.lat);
                    $.ajax({
                        url:'http://api.map.baidu.com/geocoder/v2/?ak=Ya2nSaqjT3vNrIgba1v4nfWzSxGdtgZD&location=' + r.point.lat + ',' + r.point.lng + '&output=json',
                        dataType: 'jsonp',
                        callback: 'BMap._rd._cbk43398',
                        success: function(res) {
                            console.log(res);
                            var result = res.result,
                                addressComponent = result.addressComponent,
                                adcode = addressComponent.adcode
                        } ,
                        error:function(){
    
                        }
                    });
    
                }
                else {
                    alert('failed'+this.getStatus());
                }
            },{enableHighAccuracy: true});
  • 相关阅读:
    Balanced Binary Tree
    Swap Nodes in Pairs
    Reverse Nodes in k-Group
    Reverse Linked List II
    Remove Nth Node From End of List
    Remove Duplicates from Sorted List II
    Remove Duplicates from Sorted List
    Partition List
    Merge Two Sorted Lists
    【Yii2.0】1.2 Apache检查配置文件语法
  • 原文地址:https://www.cnblogs.com/lkeji388/p/9706625.html
Copyright © 2011-2022 走看看