Geoposition realtime JavaScript Language

I'm having a problem getting this to refresh every 200ms and update the position on the map. Could someone show me where I made a mistake?

<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
function init() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showMaps, getError);
  }
  else {
    alert("Geolocalizzazione non supportata dal browser");
  }
}

function getError(error) {
  switch(error.code) {
    case 0:
      document.getElementById("status").innerHTML = "Errore sconosciuto";
      break;
    case 1:
      document.getElementById("status").innerHTML = "Richiesta rifiutata     dall'utente";
      break;
    case 2:
      document.getElementById("status").innerHTML = "La posizione non può essere determinata!";
      break;
    case 3:
      document.getElementById("status").innerHTML = "Timeout Scaduto";
      break;
  }
}

function showMaps(position) {
  var latitude = position.coords.latitude;
  var longitude = position.coords.longitude;
  var punto = new google.maps.LatLng(latitude,longitude);
  var punto2 = new google.maps.LatLng(43.771426,11.254018999999971);
  var punto3 = new google.maps.LatLng(43.7748248,11.234526599999981);

  options = {
    zoom: 13,
    center: punto,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }

  map_div = document.getElementById("my_map");
  map = new google.maps.Map(map_div, options);

  marker = new google.maps.Marker({
    position: punto,
    map: map,
    title: "Posizione Geolocalizzata"
  });

  marker2 = new google.maps.Marker({
    position: punto2,
    map: map,
    title: "Posizione Host1"
  });

  marker3 = new google.maps.Marker({
    position: punto3,
    map: map,
    title: "Posizione Host2"
  });
}

setInterval(showMaps(), 200);
</script>

<head>
<body onload="init();">

<p id="status"></p>
<div id="my_map"></div>

</body>

Answers


error happens in the last lines of the script, where you do

setInterval(showMaps(), 200);

because you call this function without required arguments.

setInterval(init, 1000)

should work.pay attention that i do (init, 1000) instead of (init(), 1000)

link (updated) http://codepen.io/robert-isaev/pen/yNPRgM


Need Your Help

Rails - number of rows in a file

ruby-on-rails file csv fastercsv

Hey. How can I get a total number of rows in a file (do not want to do it with loop). I'm reading CSV file.

How to display jquery popup window with a text area and several radio buttons?

javascript jquery html

I need to display a popup window which will ask user to select one from given radio button options(let's say 3 radio button options). Or type something in the given text area(only one can be done)