Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
- </head>
- <body>
- <div>
- latitude: <input type="text" id="latitude" value=""><br>
- longitude <input type="text" id="longitude" value="">
- </div>
- <button onclick="getLocation()">my Location</button>
- <button onclick="viewMap()">view map</button>
- <script>
- var x = document.getElementById("latitude");
- var y = document.getElementById("longitude");
- function getLocation() {
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(showPosition);
- }
- }
- function showPosition(position) {
- x.value=position.coords.latitude;
- y.value=position.coords.longitude;
- }
- function viewMap() {
- if( x.value != "" && y.value != "" ) {
- var map = "http://maps.google.com/?q=" + x.value + "," + y.value;
- window.open(map);
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment