Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <p id="demo">Click the button to get your coordinates:</p>
- <button onclick="getLocation()">Try It</button>
- <script>
- var x = document.getElementById("demo");
- function getLocation() {
- if (navigator.geolocation) {
- var optn = {
- enableHighAccuracy: true,
- timeout: Infinity,
- maximumAge: 0
- };
- var teste = navigator.geolocation.watchPosition(showPosition, err, optn);
- } else {
- x.innerHTML = "Geolocation is not supported by this browser.";
- }
- }
- function showPosition(position) {
- document.getElementById('img').src = "http://maps.googleapis.com/maps/api/staticmap?size=500x400&sensor=true&markers=color:red|"+position.coords.latitude+","+position.coords.longitude+"";
- console.log(position);
- x.innerHTML="Latitude: " + position.coords.latitude +
- "<br>Longitude: " + position.coords.longitude;
- }
- function err(err){
- console.log(err);
- }
- </script>
- <img src="" id="img"/>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement