Tracking Google Map

6 views
Skip to first unread message

Thibaut M. via StackOverflow

unread,
May 17, 2017, 5:03:11 AM5/17/17
to google-appengin...@googlegroups.com

I am developing a web application in JS or I use the map google, I have documented on all the page of https://developers.google.com/maps/documentation/javascript/examples/map- Geolocation? Hl = fr and others. But impossible to find a constant tracking. Here is my current code I did in JS:

<script type="text/javascript">
  function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
      center: {lat: 40.674, lng: -73.945},
      zoom: 19,
      scrollwheel: false,
      zoomControl: false,
      disableDoubleClickZoom: true,
      disableDefaultUI: true,
      draggable: false,
    });

    var image = 'https://image.noelshack.com/fichiers/2017/20/1494853817-
    rond.png';

    //geolocation
    if (navigator.geolocation) {
      setInterval(function(){ 

        navigator.geolocation.getCurrentPosition(function(position) {

          var pos = {
          lat: position.coords.latitude,
          lng: position.coords.longitude
          };

          var infoWindow = new google.maps.Marker({
          position: pos,
          map: map,
          icon: image,
          });

          infoWindow.setPosition(pos);
          map.setCenter(pos);

        }, 

        function() {
          handleLocationError(true, infoWindow, map.getCenter());
        });


      }, 1000);
    } else {
      // Browser doesn't support Geolocation
      handleLocationError(false, infoWindow, map.getCenter());
    }
  }


  function handleLocationError(browserHasGeolocation, infoWindow, pos) {
    infoWindow.setPosition(pos);
    infoWindow.setContent(browserHasGeolocation ?
                          'Error: The Geolocation service failed.' :
                          'Error: Your browser doesn\'t support 
                           geolocation.');
  }


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/44020150/tracking-google-map
Reply all
Reply to author
Forward
0 new messages