development

Chrome의 HTML 5 지리적 위치 프롬프트

big-blog 2020. 11. 7. 10:48
반응형

Chrome의 HTML 5 지리적 위치 프롬프트


HTML 5를 시작하고 지리적 위치를 테스트하기 시작했습니다. 그래도 약간의 속도 범프가 발생하고 있습니다 ... 내 지리적 위치를 얻으려고 할 때 크롬은 자동으로 페이지가 내 위치를 가져 오지 못하도록 차단합니다. 아래 사이트와 같은 다른 사이트에서는 발생하지 않습니다.

http://html5demos.com/geo

내가 사용중인 스크립트 :

<script type="text/javascript" JavaScript" SRC="geo.js"></script>   
<script type="text/javascript" JavaScript" SRC="Utility.js"></script> 
<script type="text/javascript" JavaScript" SRC="jquery.js"></script> 
<script type="text/javascript" JavaScript" SRC="modernizr.js"></script>  

function get_location() {

        if (geo_position_js.init()) {
            geo_position_js.getCurrentPosition(show_map, handle_error);
        }

    }
    function show_map(position) {
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;

        alert("lat:" + latitude + " long:" + longitude);


    }
    function handle_error(err) {
        alert(err.code);
        if (err.code == 1) {
            // user said no!
        }
    }

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(show_map, handle_error);
    } else {
        error('not supported');
    }

내 컴퓨터의 로컬 디렉터리에서 테스트 중이므로 "http://whatever.com/mytestpage.html"과 같은 "도메인"이 실제로는 없습니다. 이것이 내가 메시지를받지 못하는 이유입니까? 그렇다면 브라우저가 사용자의 지리적 위치를 가져 오기위한 권한을 요청하도록 강제 할 수 있으며 내 시나리오에서 가능합니까?


file:///URI 에서 위치 정보를 사용하기 위해 Chrome에는 일종의 보안 제한이 있지만, 불행히도이를 나타내는 오류를 기록하지 않는 것 같습니다. 로컬 웹 서버에서 작동합니다. Python이 설치되어있는 경우 테스트 파일이있는 디렉토리에서 명령 프롬프트를 열고 다음 명령을 실행하십시오.

python -m SimpleHTTPServer

포트 8000에서 웹 서버를 시작한 다음 (다른 것일 수도 있지만 콘솔에서 수신 대기중인 포트를 알려줍니다) http : // localhost : 8000 / mytestpage.html로 이동합니다.

Python이없는 경우 Ruby에 동등한 모듈이 있거나 Visual Web Developer Express가 내장 된 로컬 웹 서버와 함께 제공됩니다.


위의 어느 것도 나를 도왔습니다.

약간의 조사 끝에 M50 (2016 년 4 월)부터 Chrome은 이제 Geolocation에 대한 보안 출처 (예 : HTTPS)가 필요 하다는 것을 발견했습니다 .

안전하지 않은 출처에서 더 이상 사용되지 않는 기능

호스트 "localhost"는 "잠재적으로 안전"하는 특수한 것입니다. 개발 머신에 배포하는 경우 개발 중에 오류가 표시되지 않을 수 있습니다.


robertc의 답변에서 이미 언급했듯이 Chrome은 로컬 파일의 지리적 위치와 같은 특정 기능을 차단합니다. 자체 웹 서버를 설정하는 더 쉬운 대안 은 매개 변수를 사용하여 Chrome을 시작하는 --allow-file-access-from-files입니다. 그런 다음 설정에서 사용 중지하지 않은 경우 지리적 위치를 사용할 수 있습니다.


설정에서 차단되지 않았는지 확인

http://www.howtogeek.com/howto/16404/how-to-disable-the-new-geolocation-feature-in-google-chrome/


서버 뒤에서 호스팅하고 있지만 여전히 문제가있는 경우 : localhost127.0.0.1 ( 예 : http : // localhost : 8080 / 에서 http://127.0.0.1:8080/)로 변경해보십시오 .

내가 직면 한 문제는 Eclipse IDE (eclipse luna) 내에서 apache tomcat을 사용하여 사이트를 제공하고 있다는 것입니다.

내 상태 확인을 위해 Remy Sharp의 데모를 사용했습니다 .https : //github.com/remy/html5demos/blob/eae156ca2e35efbc648c381222fac20d821df494/demos/geo.html

서버에서 코드를 호스팅 했음에도 불구하고 오류 기능을 약간 조정 한 후 오류가 발생했습니다 (Firefox에서만 작동하고 크롬 및 사파리에서는 실패했습니다).

"사용자가 지리적 위치를 거부했습니다."

I made the following change to get more detailed error message:

function error(msg) {
  var s = document.querySelector('#status');
  msg = msg.message ? msg.message : msg; //add this line
  s.innerHTML = typeof msg == 'string' ? msg : "failed";
  s.className = 'fail';

  // console.log(arguments);
}

failing on internet explorer behind virtualbox IE10 on http://10.0.2.2:8080 :

"The current location cannot be determined"


The easiest way is to click on the area left to the address bar and change location settings there. It allows to set location options even for file:///

enter image description here


For an easy workaround, just copy the HTML file to some cloud share, such as Dropbox, and use the shared link in your browser. Easy.


I too had this problem when i was trying out Gelocation API. I then started IIS express through visual studio and then accessed the page and It worked without any issue in all browsers.

참고URL : https://stackoverflow.com/questions/5423938/html-5-geo-location-prompt-in-chrome

반응형