獲取當前地址

/*獲取當前位置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*/
相關文章
相關標籤/搜索