Show real-time position on map

Asked

Viewed 44 times

1

How to display the current position in real time on the map?

found this code on the internet where displays the markings on the map:

<div id="mapa" style="width:100%;height:100%;"></div>

.

< script >
  $(document).ready(function() {
    $('.sidenav').sidenav();
    $('.modal').modal();
  });


var markersData = [
  <?php do { ?> {
    lat: <?php echo $row_rs['lat']; ?>,
    lng: <?php echo $row_rs['lon']; ?>,
    //nome: "Parque de Campismo Praia da Barra",
    //morada1:"Rua Diogo Cão, 125",
    //morada2: "Praia da Barra",
    //codPostal: "3830-772 Gafanha da Nazaré" // não colocar virgula no último item de cada marcador
  },
  <?php } while ($row_rs = $rs->fetch_assoc()); ?>
];



var x = document.getElementById("demo");
var lat = document.getElementById("lat");
var lon = document.getElementById("lon");


function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition, showError);
  } else {
    x.innerHTML = "A geolocalização não é suportada por este navegador.";
  }
}

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

}

function showError(error) {
  switch (error.code) {
    case error.PERMISSION_DENIED:
      x.innerHTML = "Usuário negou a solicitação de geolocalização."
      break;
    case error.POSITION_UNAVAILABLE:
      x.innerHTML = "As informações de localização estão indisponíveis."
      break;
    case error.TIMEOUT:
      x.innerHTML = "A solicitação para obter a localização do usuário atingiu o tempo limite."
      break;
    case error.UNKNOWN_ERROR:
      x.innerHTML = "Ocorreu um erro desconhecido."
      break;
  }
} <
/script>

<
script src = "map.js" > < /script>

inserir a descrição da imagem aqui

I would like to activate the position has real time of the person, so you can know if it is near any marking.

inserir a descrição da imagem aqui

  • @Brunofonseca I put the code on my website and nothing happened. I would have to change some code?

  • Take a look at this link here

  • @adventistaam I put the code on my website and also did not give.

  • You are using the google generated key?

  • @adventistaam Yes, I am, and my website also has https.

  • Take a look at this example here

  • @adventistaam It wouldn’t be that kind of markup. It would be like this https://prnt.sc/mx1bwy the same one that appears on the android map.

  • But it is customizable

  • @adventistaam people from the sky! What a difficult business! I am not managing to make this appointment!

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.