获取当前地址

/*获取当前位置start*/function getLocation(elem){    if (navigator.geolocation)    {        //navigator.geolocation.getCurrentPosition(function(position){        var geolocation = new BMap.Geolocation();        geolocation.getCurrentPosition(function(position){            //var W_ = position.coords.latitude;//维度            //var J_ = position.coords.longitude;//经度            var W_ =position.point.lat;            var J_ =position.point.lng;            Select(W_,J_,elem);        });    }    else{        alert("没法获取当前位置");    }}var SAMPLE_POST_REVERSE = 'https://api.map.baidu.com/geocoder/v2/?ak=密钥&callback=renderReverse&s=1';var safe = '';var pois;function showReverseURL(latitude,longitude,elem){    safe = SAMPLE_POST_REVERSE;    safe += "&location=" + latitude + "," + longitude;    safe += "&output=json";    safe += '&pois=' + pois;};function Select(latitude,longitude,elem){    var script = document.createElement('script');    script.type = 'text/javascript';    showReverseURL(latitude,longitude,elem);    var newURL = safe.replace('密钥', '密钥值');    script.src = newURL;    document.body.appendChild(script);};function renderReverse(response){    var val = '';    if (response.status)    {        alert("无正确的返回结果");        return;    }    var location = response.result.location;    if(response.result.formatted_address == "")    {        alert("无正确的返回结果");    }    else    {        val=response.result.formatted_address+response.result.sematic_description;    }    if (pois == 1)    {        val="";    }    window.elem.val(val);//  $("#address").val(val);    return;}/*获取当前位置end*/
相关文章
相关标签/搜索