Findlocation

From MobileRead
Jump to: navigation, search

This is a sample of HTML5 location code use to find Geolocation.

The text below should be pasted into an empty html page and saved. When you open the page with your browser (file:///) it should create a box that says: "Show Position". Click the box to see your current location. Note you may have to acknowledge acceptance to provide this data. You may need to click again depending on the browser. If it doesn't work your browser doesn't support HTML5.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get Current Position</title> <script> function showPosition() { if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")"; document.getElementById("result").innerHTML = positionInfo; }); } else { alert("Sorry, your browser does not support HTML5 geolocation."); } } </script> </head> <body> <div id="result"> <!--Position information will be inserted here--> </div> <button type="button" onclick="showPosition();">Show Position</button> </body> </html>

[edit] For more information

Personal tools
Namespaces

Variants
Actions
Navigation
MobileRead Networks
Toolbox