More actions
imported>pkccr1 No edit summary |
(Repair MoniWiki formatting after migration) |
||
| Line 67: | Line 67: | ||
= 예제 = | = 예제 = | ||
* http://html5demos.com/ | * http://html5demos.com/ | ||
Revision as of 14:01, 26 March 2026
[[pagelist(html5)]]
Geolocation API?
- 프로그램을 실행하는 디바이스의 위치 정보를 얻기 위한 API
- 모바일 애플리케이션과 연동하여 사용
- 고급 레벨의 API - GPS를 이용하는지 네트워크 정보를 이용하는지는 알수 없으나
디바이스나 네트워크의 종류에 관계없이 동작!
사용 방법
- Geolocation API 관련 메서드는 모두 window.navigator 객체에 정의
getCurrentPosition()
- 현재 위치를 한번만 받는 메서드
namigator.geolocation.getCurrentPosition(function(position){
alert("위도:" + position.coords.latitude +
"경도 :" + position.coords.longitude);
});
- 위치 정보 객체의 속성
| coords 속성 | 설명 |
| latitude | 위도 |
| longitude | 경도 |
| altitude | 표고 |
| accuracy | 위도와 경도의 오차 |
| altitudeAccuracy | 표고의 오차 |
| heading | 진행방향 |
| speed | 진행 속도 |
watchPosition()
- 현재 위치를 계속 추적
- clearWatch()가 호출되면 종료
추가 기능
| 속성 | 설명 |
| enableHighAccuracy | 정확도가 높은 위치 정보 요청 |
| timeout | 위치 정보 확인에 시간제한 설정 |
| maximumAge | 유효 기간 설정 |