2012-04-03 3 views
0

Firefox에서 사용하는 동안 오류 2 (위치를 사용할 수 없음)가 표시되는데 내 위치와 관련하여 브라우저에 권한을 부여했지만 W3C 위치 정보 API를 구현하려고하는데 오류 1이 발생합니다. (Permission denied) 크롬에서 시도하는 동안.W3C geolocation, 오류 : 위치를 사용할 수 없음

HTML 버튼 JS 함수를 호출 :

  function geo(){ 

        if (navigator.geolocation) { 

          navigator.geolocation.getCurrentPosition(
           displayPosition, 
           displayError); 
        } 
       else { 
         alert("Geolocation is not supported by this browser"); 
        } 

     function displayPosition(position) { 
       alert("Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude); 
         } 
     function displayError(error) { 
       var errors = { 
        1: 'Permission denied', 
        2: 'Position unavailable', 
        3: 'Request timeout' 
        }; 
       alert("Error: " + errors[error.code]); 
        } 


    } 

    function canvas() { 
       var canvas = document.getElementById("canv"); 
       var context = canvas.getContext("2d"); 
       context.fillStyle="red"; 
       context.strokeStyle="blue"; 
       context.strokeRect(50,25,50,60); 
       context.fillRect(50,25,50,60); 
       context.strokeStyle="green"; 
       context.moveTo(0,0); 
       context.lineTo(300,150); 
       context.stroke(); 
       context.fillStyle="blue"; 
       context.font="bold 12px Arial"; 
       context.textAlign="start"; 
       context.fillText("This is some Text",50,110); 
       var gradient=context.createLinearGradient(0,0,100,100); 
       gradient.addColorStop(0,"white"); 
       gradient.addColorStop(1,"black"); 
       context.fillStyle=gradient; 
       context.fillRect(50,50,100,100); 
       context.fillText("Im using Gradient!",60,10); 
       context.drawImage(image, 20,20); 


        }; 

답변

1

: 우리는 지리적 위치 API

<input type="button" name="canbutt" value="draw c" onClick="javascript:geo()"/> 

그리고 내 JS 코드에 대해 이야기하려고 지금

을 다음은 내 코드입니다 Geolocation 사용시 제한 사항은 file:/// URI입니다. 웹 서버에서 페이지를 업로드 해보십시오 (로컬 서버에서도 작동).

관련 문제