Navigator Geolocation, questions and problems

0

I'm having a problem with navigator, I'm trying to get it to refresh the map and I can get and check the user move update for the map, but I have no idea, I thought about using a reload map function, however reloading it all and getting information from the array can demand time, battery and internet connection. Does anyone have a clue how to do this and avoid / send error images to the user when the same deny the location? OBs I already have a database, however I do not know how to put 2 active users on the map showing for everyone.

 function Geolocation(){
   if(window.navigator.geolocation){
   // função criada para pegar localização
    var array = [];
    window.navigator.geolocation.watchPosition(function(position, options, accuracy) {

   array = [];
   var lat = position.coords.latitude;
   var lon = position.coords.longitude;
   var vel = position.coords.speed;
   var accuracy = position.coords.accuracy;
    array.push(lat, lon, vel);
    console.log(array);
    window.latitude = array[0];
    window.longitude = array[1];
    window.velocidade = array[2];

}); 

}    }

    function initMap(){

    //Opções do mapa
    var options = {
      minZoom:16,
      maxZoom:18,
      zoom:17,
      zoomControl: false,
      scaleControl: false,
      fullscreenControl: false,
      streetViewControl: false,
      panControl: false,
      signInControl: false,
      mapTypeControl: false,
      noClear: true,
      disableDefaultUI: false,
    //  center:{lat:-24.1688528,lng:-46.7855251}
      center:{lat:window.latitude, lng:window.longitude}

    };

    //Mapa
    var map = new google.maps.Map(document.getElementById('mapa'), options);

    //Marcação
    var marker = new google.maps.Marker({
       position:{lat:window.latitude,lng:window.longitude},
     // position:{lat:-24.1688528,lng:-46.7855251},
      map: map,
      icon: 'img/pinpoint.png'
    });

  }
    
asked by anonymous 07.06.2018 / 04:32

1 answer

0

Maybe you can use a function that stays running all the time as it is:

            var lat;
            var lng;


          //manter gps rodando

          function Temporizador(initiate) {
          if (initiate !== true) {

            navigator.geolocation.getCurrentPosition(function (pos) {
             lat = pos.coords.latitude;
             lng = pos.coords.longitude;
            if (lat == null) {
              alert("GPS not activated!");
            }
        else{
         L.marker([lat,lng]).addTo(mapabase);
          }
           });

           }
         setTimeout(Temporizador, 5000);
}

      $(function() {
    Temporizador(true);
});

I'm already telling you that every geolocation function was blocked by google chrome when you play it in the air, it's functional, now for tests locally it works, so that it works with your site in the air your site has to have the certificate security (HTTPS). Oh and this is a block of google chrome, in mozila works perfectly still the geolocation function. I hope I helped you

    
10.09.2018 / 15:00