Created
January 7, 2014 09:18
-
-
Save dkdndes/8296827 to your computer and use it in GitHub Desktop.
Example: Geolocation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset=utf-8 /> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <p id="geo">Click the button to get your coordinates:</p> | |
| <button onclick="getLocation()">Try It</button> | |
| </body> | |
| </html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var x = document.getElementById("geo"); | |
| function getLocation() { | |
| if (navigator.geolocation) { | |
| navigator.geolocation.getCurrentPosition(showPosition); | |
| } else { | |
| x.innerHTML = "Geolocation is not supported by this browser."; | |
| } | |
| } | |
| function showPosition(position) { | |
| x.innerHTML = "Latitude: " + position.coords.latitude + | |
| "<br>Longitude: " + position.coords.longitude; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment