asimryu

html5-geolocation 1

Jun 11th, 2014
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.92 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
  5. </head>
  6. <body>
  7.  
  8. <div>
  9. latitude: <input type="text" id="latitude" value=""><br>
  10. longitude <input type="text" id="longitude" value="">
  11. </div>
  12.  
  13. <button onclick="getLocation()">my Location</button>
  14. <button onclick="viewMap()">view map</button>
  15. <script>
  16. var x = document.getElementById("latitude");
  17. var y = document.getElementById("longitude");
  18.  
  19. function getLocation() {
  20.     if (navigator.geolocation) {
  21.         navigator.geolocation.getCurrentPosition(showPosition);
  22.     }
  23. }
  24.  
  25. function showPosition(position) {
  26.     x.value=position.coords.latitude;
  27.                 y.value=position.coords.longitude;
  28. }
  29.  
  30. function viewMap() {
  31.     if( x.value != "" && y.value != "" ) {
  32.         var map = "http://maps.google.com/?q=" + x.value + "," + y.value;
  33.         window.open(map);
  34.     }
  35. }
  36. </script>
  37.  
  38. </body>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment