Mais conteúdo relacionado
Semelhante a HTML5 Geolocation API (9)
Mais de Департамент Стратегических Технологий (20)
HTML5 Geolocation API
- 1. HTML5 Geolocation API Никита Лукьянец Департамент стратегических технологий Microsoftnikital@microsoft.com@nikiluk, Twitter
- 2. О чем пойдёт речь? К чему нам HTML5 Что значит “локально” Use Cases Пару простых примеров
- 18. W3C Geolocation API navigator.geolocation.getCurrentPosition(function(pos){ //show map at (pos.coords.latitude, pos.coords.longitude) });
- 20. W3C Geolocation API Latest Published Version: http://www.w3.org/TR/geolocation-API/ Latest Editor's Draft: http://dev.w3.org/geo/api/spec-source.html
- 21. Объекты Position и Coordinates interface Position { readonly attribute Coordinates coords; readonly attribute DOMTimeStamptimestamp; }; interface Coordinates { readonly attribute double latitude; readonly attribute double longitude; readonly attribute double altitude; readonly attribute double accuracy; readonly attribute double altitudeAccuracy; readonly attribute double heading; readonly attribute double speed; };
- 22. + callback function showMap(pos) { //show map at pos.coords.latitude, pos.coords.longitude } function showError(err) { alert(err.message + ‘, ’ + err.code); } navigator.geolocation.getCurrentPosition(showMap, showError);
- 24. + Объект ошибки локации interface PositionError { const unsigned short UNKNOWN_ERROR = 0; const unsigned short PERMISSION_DENIED = 1; const unsigned short POSITION_UNAVAILABLE = 2; const unsigned short TIMEOUT = 3; readonly unsigned short code; readonlyDOMStringmessage; };
- 25. + Опции interface PositionOptions{ attribute booleanenableHighAccuracy; attribute long timeout; attribute long maximumAge; };
- 26. Всё вместе function showMap(pos) { //show map at pos.coords.latitude, pos.coords.longitude } function showError(err) { alert(err.message + ‘, ’ + err.code); } navigator.geolocation.getCurrentPosition(showMap, showError, {enableHighAccuracy:true, maximumAge:300000, timeout:0});
- 27. Слежение! function moveMap(pos) { //update map to pos.coords.latitude, pos.coords.longitude } function showError(err) { alert(err.message + ‘, ’ + err.code); } // Track location with periodic updates watchId = navigator.geolocation.watchPosition(moveMap, showError); function stopTracking() { navigator.geolocation.clearWatch(watchId); }
- 28. Резюме Геолокация = релевантность Гибридное решение может быть дешевле HTML5 => мобильный веб