html5 返回當前地理位置的座標點(經緯度)

來源:互聯網
上載者:User

標籤:rip   oct   oca   Google地圖   lis   show   ntp   one   cat   

BAIDU

<!DOCTYPE html><html><body><p id="demo">點擊這個按鈕,獲得您的座標:</p><button onclick="getLocation()">試一下</button><script>var x=document.getElementById("demo");function getLocation()  {  if (navigator.geolocation)    {    navigator.geolocation.getCurrentPosition(showPosition);    }  else{x.innerHTML="Geolocation is not supported by this browser.";}  }function showPosition(position)  {  x.innerHTML="Latitude: " + position.coords.latitude +   "<br />Longitude: " + position.coords.longitude;      }</script></body></html>

GOOGLE

<!DOCTYPE html><html><head><meta charset="utf-8" /><title>GIS開發利用html5擷取經緯度</title></head><body><span id="support">將以下的經緯度輸入Google地圖:</span><div id="show">緯度:<span id="latitude"></span><br />經度:<span id="longitude"></span><br />經緯度準確度:<span id="accuracy"></span><br />海拔:<span id="altitude"></span><br />海拔高度的準確度:<span id="altitudeAcuracy"></span><br />朝向:<span id="heading"></span><br />速度:<span id="speed"></span></div><script type="text/javascript">var doc = document,    latitude = doc.getElementById(‘latitude‘),    longitude = doc.getElementById(‘longitude‘),    accuracy = doc.getElementById(‘accuracy‘),    altitude = doc.getElementById(‘altitude‘),altitudeAcuracy = doc.getElementById(‘altitudeAcuracy‘),heading = doc.getElementById(‘heading‘),speed = doc.getElementById(‘speed‘),support = doc.getElementById(‘support‘),    showDiv = doc.getElementById(‘show‘);function lodeSupport(){    if(navigator.geolocation){        support.innerHTML = ‘將以下的經緯度輸入Google地圖(緯度 經度)查看自己位置:‘;        showDiv.style.display = ‘block‘;        navigator.geolocation.getCurrentPosition(updataPosition,showError);    }else{        support.innerHTML = ‘對不起,瀏覽器不支援!

‘; showDiv.style.display = ‘none‘; }}function updataPosition(position){ var latitudeP = position.coords.latitude, longitudeP = position.coords.longitude, accuracyP = position.coords.accuracy,altitudeP = position.coords.altitude,altitudeAcuracyP = position.coords.altitudeAcuracy,headingP = position.coords.heading,speedP = position.coords.speed; latitude.innerHTML = latitudeP; longitude.innerHTML = longitudeP; accuracy.innerHTML = accuracyP;altitude.innerHTML = altitudeP;altitudeAcuracy.innerHTML = altitudeAcuracyP;heading.innerHTML = headingP;speed.innerHTML = speedP;}function showError(error){ switch(error.code) { case error.PERMISSION_DENIED: showDiv.innerHTML="使用者拒絕訪問地理位置" break; case error.POSITION_UNAVAILABLE: showDiv.innerHTML="地理位置資訊無法擷取" break; case error.TIMEOUT: showDiv.innerHTML="擷取位置時間逾時" break; case error.UNKNOWN_ERROR: showDiv.innerHTML="我擦,這是一個未知的錯誤" break; }}window.addEventListener(‘load‘, lodeSupport , true);</script></body></html>




html5 返回當前地理位置的座標點(經緯度)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.