차근차근/JAVA JSP

지오로케이션 사용하기 geolocation

예쁜꽃이피었으면 2015. 1. 6. 17:57

지오로케이션 사용하기

https://developer.mozilla.org/ko/docs/WebAPI/Using_geolocation



http://www.tutorialspoint.com/html5/geolocation_watchposition.htm


Geolocation watchPosition() API







검색어 : navigator.geolocation.watchposition


geolocation Demo_watchPosition

http://kkams.net/21

HTML5의 기능인 geolocation 의 기능중 위치 정보를 계속 조회하는 watchPosition의 기능을 알아보겠다.

아래 버튼을 클릭하면 watchPosition 메서드를 이용하여 위치관련 정보를 조회/종료를 할수 있다.

 


버튼 클릭시 호출 되는 자바스크립트의 소스는 아래와 같다.

  1. <script type="text/javascript">  
  2.         var loopCount = 0; //조회수  
  3.         //위치 정보 확인하기  
  4.         function showWatchPositionInfo(pos) {  
  5.             try {  
  6.                 document.getElementById("divPostionInfo").innerHTML = "<ul class='list'><li>조회 횟수 : " + loopCount++ +  
  7.                 "</li><li>timestamp : " + pos.timestamp +  
  8.                 "</li><li>latitude : " + pos.coords.latitude +  
  9.                 "</li><li>longitude : " + pos.coords.longitude +  
  10.                 "</li><li>altitude : " + pos.coords.altitude +  
  11.                 "</li><li>accuracy : " + pos.coords.accuracy +  
  12.                 "</li><li>altitudeAccuracy : " + pos.coords.altitudeAccuracy +  
  13.                 "</li><li>heading : " + pos.coords.heading +  
  14.                 "</li><li>speed : " + pos.coords.speed + "</li></ul>";  
  15.             } catch (ex) {  
  16.                 alert(ex.message);  
  17.             }  
  18.         }  
  19.         //에러발생시 호출되는 함수  
  20.         function handleError(error) {  
  21.             document.getElementById("divPostionInfo").innerHTML = "브라우저가 기능을 지원하지 않습니다.";  
  22.         }  
  23.   
  24.         var watchId;  
  25.         //위치 추적 시작하기  
  26.         function startWatchPosition() {  
  27.             if (typeof (navigator.geolocation) == 'undefined') {  
  28.                 document.getElementById("divPostionInfo").innerHTML = "브라우저가 기능을 지원하지 않습니다.";  
  29.             } else {  
  30.                 watchId = navigator.geolocation.watchPosition(showWatchPositionInfo, handleError);  
  31.             }  
  32.         }  
  33.         //위치추적 종료하기  
  34.         function stopWatchPosition() {  
  35.             try {  
  36.                 navigator.geolocation.clearWatch(watchId);  
  37.             } catch (ex) {  
  38.                 alert(ex.message);  
  39.             }  
  40.         }  
  41.     </script>  

+

<p>

<input type="button" value="위치 정보 조회 시작" onclick="startWatchPosition();">

</p>

<div id="divPostionInfo" style="width: 300px; height: 200px; border: 1px solid ; overflow: auto;font-size: 9pt; padding: 5 5 5 5;">

</div>


http://stackoverflow.com/questions/2267513/using-navigator-geolocation-getcurrentposition-in-webview-on-android-2-0-phone

Using navigator.geolocation.getCurrentPosition in WebView on Android 2.0+



[HTML5] 자바스크립트 API (Geolocation)

http://deviant86.tistory.com/478


반응형