2017-10-26 3 views
0

html5 geolocation api에 대해 배우고 있습니다. 연습용으로이 간단한 코드를 작성했습니다. 그러나 "위치 정보를 사용할 수 없음"상태가 계속되고, 나는 그 이유를 모른다. 나는 이것에 아주 새롭, 약간 도움을 평가할 것입니다.html5 geolocation을 가져올 수 없습니다.

여기 내 코드입니다. var userLocation = document.querySelector(".location");

document.getElementById("btn").addEventListener("click", function(){ 
    if(navigator.geolocation){ 
    navigator.geolocation.getCurrentPosition(showPosition, showError); 
    userLocation.textContent = "Checking Location..."; 
    } 
    else { 
    userLocation.textContent = "Unable to retrieve location.."; 
    } 
}); 

function showPosition(position){ 
    userLocation.textContent = position.coords.longitude; 
} 

function showError(error){ 
    switch(error.code){ 
    case error.PERMISSION_DENIED: 
      alert("User denied the request for Geolocation."); 
      break; 
     case error.POSITION_UNAVAILABLE: 
      alert("Location information is unavailable."); 
      break; 
     case error.TIMEOUT: 
      alert("The request to get user location timed out."); 
      break; 
     case error.UNKNOWN_ERROR: 
      alert("An unknown error occurred."); 
      break; 
    } 

} 

답변

0

당신은 또한 당신이 위치에 권한이 거부 적이 있는지 확인 HTTPS를 통해 페이지를로드되어 있는지 확인합니다.

+0

답장을 보내 주셔서 감사합니다. 제 PCI 카드가 Linux 우분투에서 작동하지 않는 문제가있었습니다. 그래도 도움을 주셔서 감사합니다. –

관련 문제