Advertisement
rogerin

api Geolocatiozador

Sep 1st, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.00 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p id="demo">Click the button to get your coordinates:</p>
  6.  
  7. <button onclick="getLocation()">Try It</button>
  8.  
  9. <script>
  10. var x = document.getElementById("demo");
  11.  
  12. function getLocation() {
  13.     if (navigator.geolocation) {
  14.         var optn = {
  15. enableHighAccuracy: true,
  16.             timeout: Infinity,
  17.             maximumAge: 0
  18.         };
  19.         var teste = navigator.geolocation.watchPosition(showPosition, err, optn);
  20.     } else {
  21.         x.innerHTML = "Geolocation is not supported by this browser.";
  22.     }
  23. }
  24.  
  25. function showPosition(position) {
  26.     document.getElementById('img').src = "http://maps.googleapis.com/maps/api/staticmap?size=500x400&sensor=true&markers=color:red|"+position.coords.latitude+","+position.coords.longitude+"";
  27.    
  28.     console.log(position);
  29.     x.innerHTML="Latitude: " + position.coords.latitude +
  30.     "<br>Longitude: " + position.coords.longitude; 
  31.    
  32. }
  33. function err(err){
  34. console.log(err);
  35.     }
  36. </script>
  37.  
  38.     <img src="" id="img"/>
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement