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('定位失敗,用戶拒絕請求地理定位'); break;case error.POSITION_UNAVAILABLE: alert('定位失敗,位置信息是不可用'); break;case error.TIMEOUT: alert('定位失敗,請求獲取用戶位置超時'); 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)常這樣,還有某些手機也會這樣,后來沒辦法定位失敗用ip定位了,你用火狐和國內(nèi)瀏覽器調(diào)試看。
相關(guān)文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關(guān)于進程間發(fā)送句柄的一點疑問5. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?6. 實現(xiàn)bing搜索工具urlAPI提交7. 配置Apache時,添加對PHP的支持時語法錯誤8. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化9. javascript - 移動端上不能實現(xiàn)拖拽布局嗎?10. phpstudy8.1支持win11系統(tǒng)嗎?

網(wǎng)公網(wǎng)安備