{"size": 2038, "ext": "js", "max_stars_repo_path": "app/vendor/geolocation.js", "max_stars_repo_name": "salomvary/outdoormaps", "max_stars_repo_stars_event_min_datetime": "2015-11-20T14:08:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-06T09:32:36.000Z", "max_issues_repo_path": "app/vendor/geolocation.js", "max_issues_repo_name": "salomvary/outdoormaps", "max_issues_repo_issues_event_min_datetime": "2015-08-10T08:20:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T22:27:18.000Z", "max_forks_repo_path": "app/vendor/geolocation.js", "max_forks_repo_name": "salomvary/outdoormaps", "max_forks_repo_forks_event_min_datetime": "2016-10-26T12:37:45.000Z", "max_forks_repo_forks_event_max_datetime": "2016-10-26T12:37:45.000Z"}
{"max_stars_count": 3, "max_issues_count": 16, "max_forks_count": 1, "avg_line_length": 26.1282051282, "max_line_length": 109, "alphanum_fraction": 0.6800785083}
// copied from
// github:gwilson/getAccurateCurrentPosition/master#geo.js
/**
 * @param {*} geolocationSuccess
 * @param {*} geolocationError
 * @param {*} geoprogress
 * @param {*} options
 */
export function getAccurateCurrentPosition(
  geolocationSuccess,
  geolocationError,
  geoprogress,
  options
) {
  /**
   * @type {*}
   */
  var lastCheckedPosition;
  var locationEventCount = 0;

  options = options || {};

  /**
   * @param {*} position
   */
  var checkLocation = function (position) {
    lastCheckedPosition = position;
    ++locationEventCount;
    // We ignore the first event unless it's the only one received because some devices seem to send a cached
    // location even when maxaimumAge is set to zero
    if (
      position.coords.accuracy <= options.desiredAccuracy &&
      locationEventCount > 0
    ) {
      clearTimeout(timerID);
      navigator.geolocation.clearWatch(watchID);
      foundPosition(position);
    } else {
      geoprogress(position);
    }
  };

  var stopTrying = function () {
    navigator.geolocation.clearWatch(watchID);
    foundPosition(lastCheckedPosition);
  };

  /**
   * @param {*} error
   */
  var onError = function (error) {
    clearTimeout(timerID);
    navigator.geolocation.clearWatch(watchID);
    geolocationError(error);
  };

  /**
   * @param {*} position
   */
  var foundPosition = function (position) {
    geolocationSuccess(position);
  };

  if (!options.maxWait) options.maxWait = 10000; // Default 10 seconds
  if (!options.desiredAccuracy) options.desiredAccuracy = 20; // Default 20 meters
  if (!options.timeout) options.timeout = options.maxWait; // Default to maxWait

  options.maximumAge = 0; // Force current locations only
  options.enableHighAccuracy = true; // Force high accuracy (otherwise, why are you using this function?)

  var watchID = navigator.geolocation.watchPosition(
    checkLocation,
    onError,
    options
  );
  var timerID = setTimeout(stopTrying, options.maxWait); // Set a timeout that will abandon the location loop
}
