Click here to Skip to main content
15,513,571 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make it so when a truck driver presses a button when he starts for the day, i can see what his location is at that very moment so i know where my drivers are starting from.


I am trying to get it when someone gives acces to their location you can get a straight adress out of it as a variable. it just needs to be city and a country.

like this: Nottingham, NG1 1AJ, UK
Here the link as an example: https://www.mapdevelopers.com/what-is-my-address.php

i can only find reverse geocoding where it just shows the location on the map.
below code uses reverse geocoding but gets an adress on a map.
i am trying to get it as a variable output to show in an app.
Thanks for the help!

What I have tried:

<!DOCTYPE html>
   <html lang="en">
   <head>
       <meta charset="UTF-8">
       <meta http-equiv="X-UA-Compatible" content="IE=edge">
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <title>Geolocation</title>
   </head>
   <body>
       <a href="#" id="get_location"><button>Get location</button></a>

       <div id="map">
           <iframe id="google_map"
           width="1000"
           height="700"
           frameborder="0"
           scrolling="no"
           marginheight="0"
           marginwidth="0"
           src="https://maps.google.com?output=embed"
           ></iframe>
   </div>

       <script>
           var x = document.getElementById("demo");
   function getLocation() {
     if (navigator.geolocation) {
       navigator.geolocation.getCurrentPosition(showPosition);
     } else {
       x.innerHTML = "Locatie niet supported door jouw browser.";
     }
   }

   function showPosition(position) {
     x.innerHTML = "Latitude: " + position.coords.latitude +
     "<br>Longitude: " + position.coords.longitude;
   }

   var c = function(pos) {
       var lat     = pos.coords.latitude
           long    = pos.coords.longitude
           coords  = lat + ', ' + long;

           document.getElementById('google_map').setAttribute('src', 'https://maps.google.com/?q='+ coords +'0&z=60&output=embed');
   }

       document.getElementById('get_location').onclick = function() {
           navigator.geolocation.getCurrentPosition(c);
           return false;
   }


   </script>

   </body>
   </html>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900