JS通过百度地图API获取当前定位信息

$(function(){
 var latlon=null;
            //ajax获取用户所在经纬度
            $.ajax({
                url:"http://api.map.baidu.com/location/ip?ak=bFNYmleHunu49WxpIlCN8QxTpzs93c8V&coor=bd09ll",
                type:"POST",
                dataType:"jsonp",
                success:function(data){
                    latlon=data.content.point.y+","+data.content.point.x;
                    //ajax根据经纬度获取省市区
                    $.ajax({
                        type: "POST",
                        dataType: "jsonp",
                        url: 'http://api.map.baidu.com/geocoder/v2/?ak=C93b5178d7a8ebdb830b9b557abce78b&callback=renderReverse&location='+latlon+'&output=json&pois=0',
                        success: function (json) {
                            if(json.status==0){
                                console.log(json.result.addressComponent.province+"-"+json.result.addressComponent.city+"-"+json.result.addressComponent.district);
                            }
                        }
                    });
                }
            });
})

猜你喜欢

转载自www.cnblogs.com/wt-vip/p/9121756.html