cyklokoalicia/OpenSourceBikeShare

Keeps loading location on Android

ewooonk opened this issue · 0 comments

The web-app keeps reloading the location on Android and ignores maximumAge. Therefore the overlay is shown more or less all the time.

Proposed solution

function changelocation(location)
{
    var now = new Date();
    if(lastUpdateTime && now.getTime() - lastUpdateTime.getTime() < 15000){
        console.log("Ignoring position update");
        return;
    }
    lastUpdateTime = now;
   if (location.coords.latitude!=$("body").data("mapcenterlat") || location.coords.longitude!=$("body").data("mapcenterlong"))
      {
      $("body").data("mapcenterlat", location.coords.latitude);
      $("body").data("mapcenterlong", location.coords.longitude);
      map.removeLayer(circle);
      circle = L.circle([$("body").data("mapcenterlat"), $("body").data("mapcenterlong")],40*5, {
      color: 'green',
      fillColor: '#0f0',
      fillOpacity: 0.1
      }).addTo(map);
      map.setView(new L.LatLng($("body").data("mapcenterlat"), $("body").data("mapcenterlong")), $("body").data("mapzoom"));
      if (window.ga) ga('send', 'event', 'geolocation', 'latlong', $("body").data("mapcenterlat")+","+$("body").data("mapcenterlong"));
      savegeolocation();
      }
}

See also: https://stackoverflow.com/questions/35294154/cordova-geolocation-watchposition-frequency-is-higher-than-the-options-allow-it/35310256