0
2.8kviews
Explain Geo-location and web worker with an example in HTML 5 & CSS 3.
1 Answer
written 6.2 years ago by |
<!DOCTYPE html> <html> <style> button{font:1em Arial; background:#fa4b2a; color:#fff;} p{font:1em Verdana; color:#fa4b2a;} </style> <body> <p id="output"></p> <button onclick="getCoordinates()"> Click here to find your current location</button> <script> var geo=document.getElementById("output"); function getCoordinates() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(currentPosition); } else{geo.innerHTML="Please upgrade your browser.";} } function currentPosition(pos) { geo.innerHTML="(Latitude , Longitude)" + "<br>" + "(" + pos.coords.latitude + " , " + pos.coords.longitude + ")"; } </script> </body> </html>
<script>var worker = new worker(‘workerscript.js’)</script>
worker.onmessage = function (event) { alert(event.data); };
code of onmessage event handler is used to receive messages from workerscript.js postMessage(some_data);
workerscript.js files includes the postMessage() function for communication with the Web page.worker.terminate();
worker = undefined;