html5 geolocation 總是說位置不可用
問題描述
<script>
getLocation();function getLocation(){ if (navigator.geolocation){navigator.geolocation.getCurrentPosition(showPosition,showError); }else{alert('瀏覽器不支持地理定位。'); }}function showError(error){ switch(error.code) {case error.PERMISSION_DENIED: alert('定位失敗,用戶拒絕請(qǐng)求地理定位'); break;case error.POSITION_UNAVAILABLE: alert('定位失敗,位置信息是不可用'); break;case error.TIMEOUT: alert('定位失敗,請(qǐng)求獲取用戶位置超時(shí)'); break;case error.UNKNOWN_ERROR: alert('定位失敗,定位系統(tǒng)失效'); break; }}function showPosition(position){ var lat = position.coords.latitude; //緯度 var lag = position.coords.longitude; //經(jīng)度 alert(’緯度:’+lat+’,經(jīng)度:’+lag);}
</script>
問題解答
回答1:用chrome我經(jīng)常這樣,還有某些手機(jī)也會(huì)這樣,后來沒辦法定位失敗用ip定位了,你用火狐和國(guó)內(nèi)瀏覽器調(diào)試看。
相關(guān)文章:
1. javascript - vscode alt+shift+f 格式化js代碼,通不過eslint的代碼風(fēng)格檢查怎么辦。。。2. javascript - 如何將一個(gè)div始終固定在某個(gè)位置;無論屏幕和分辨率怎么變化;div位置始終不變3. html5 - 有可以一次性把所有 css外部樣式轉(zhuǎn)為html標(biāo)簽內(nèi)style=" "的方法嗎?4. javascript - 有什么比較好的網(wǎng)頁版shell前端組件?5. java - 如何寫一個(gè)intellij-idea插件,實(shí)現(xiàn)編譯時(shí)修改源代碼的目的6. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標(biāo)?7. java 中Long 類型如何轉(zhuǎn)換成Double?8. javascript - 求解答:實(shí)例對(duì)象調(diào)用constructor,此時(shí)constructor內(nèi)的this的指向?9. html - vue項(xiàng)目中用到了elementUI問題10. javascript - [js]為什么畫布里不出現(xiàn)圖片呢?在線等
