GPS 수신
// 작성일자 : 2017-04-21
최근 크롬 버전에서 GPS가 geolocation API 로 수신되지 않는다.
다음과 같은 경고메시지를 크롬 브라우저의 개발자 도구에서 확인할 수 있다.
getCurrentPosition() and watchPosition() no longer work on insecure origins. ... use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
요약하면 보안상의 이유로 HTTPS를 사용하라는 이야기이다.
HTTPS는 HTTP 와 SSL을 함께 사용하는 보안 프로토콜인데, 이를 적용하려면 여러가지 해야할 일이 많아진다.
해서 다음과 같은 해결방법을 찾았다.
참고 : http://jsfiddle.net/gogs/jwt9f1o3/
var apiGeolocationSuccess = function(position) {
alert("API geolocation success!\n\nlat = " + position.coords.latitude + "\nlng = " + position.coords.longitude);
};
var tryAPIGeolocation = function() {
jQuery.post( "https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyDCa1LUe1vOczX1hO_iGYgyo8p_jYuGOPU", function(success) {
apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}});
})
.fail(function(err) {
alert("API Geolocation error! \n\n"+err);
});
};
var browserGeolocationSuccess = function(position) {
alert("Browser geolocation success!\n\nlat = " + position.coords.latitude + "\nlng = " + position.coords.longitude);
};
var browserGeolocationFail = function(error) {
switch (error.code) {
case error.TIMEOUT:
alert("Browser geolocation error !\n\nTimeout.");
break;
case error.PERMISSION_DENIED:
if(error.message.indexOf("Only secure origins are allowed") == 0) {
tryAPIGeolocation();
}
break;
case error.POSITION_UNAVAILABLE:
alert("Browser geolocation error !\n\nPosition unavailable.");
break;
}
};
var tryGeolocation = function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
browserGeolocationSuccess,
browserGeolocationFail,
{maximumAge: 50000, timeout: 20000, enableHighAccuracy: true});
}
};
tryGeolocation();
동작 확인 완료!
반응형
'Java Story' 카테고리의 다른 글
[ Spring ] 비디오 스트리밍 (3) | 2016.10.14 |
---|---|
[ Spring ] image resource (0) | 2016.10.13 |
[ Eclipse Short cut ] getter setter (0) | 2016.09.07 |
[이클립스] 프로젝트 패키지별로 보기 (1) | 2016.08.29 |
[ 서버 ] Ubuntu 14.04-server 기반 tomcat서버 세팅 (0) | 2016.08.26 |
[JAVA] 이클립스 비트버켓(bitbucket연동) link (0) | 2016.08.22 |
[ JAVA ] 성능을 업그레이드?? (링크) (0) | 2016.06.01 |
[ Spring ] @ModelAttribute와 @SessionAttributes의 이해와 한계 (링크) (0) | 2016.05.23 |