<commit_before>// steps = 0 => coming from whereis2.html i.e. not show steps
// steps = 1 => coming from whereis-text.html i.e. show steps
function loader(method, steps) {
    var state = document.readyState;	

    if (typeof(localStorage) == 'undefined' ) {
	alert('Upgrade your browser as it does not support HTML5 localStorage.');
    } 

    if (state == 'loaded' || state == 'complete') {
	method(steps);
    } else {
        if (navigator.userAgent.indexOf('Browzr') > -1) {
	    setTimeout(method(steps), 250);
        } else {
	    document.addEventListener('deviceready',method(steps),false);
	}
    }
}

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

function getLocationFromStore() {
    var gpsstore = new Lawnchair({table: 'mygps', adaptor: 'dom'});
    var destination;
    var to_lat;
    var to_long;
    var result = 0;

    // retrieve my data from my store
    gpsstore.get('default', function(r) {
	if(r !== null) {
	    result = 1;
    	    console.log(r);
	    destination = r.value.name;
	    to_lat = r.value.latitude;
	    to_long = r.value.longitude;
	}
    });

    // gpsstore.get('destination', function(r) {
    //     destination = r.value;
    // });

    if(result) {
	$('.content').append(destination + " (lat: " + to_lat + ", long: " + to_long + ")");
	$('.content').append('<br /><a href="whereis2.html" rel="external">watch on map</a>');
    } else {
	$('.content').append("No saved positions, park your car first!");
    }

}

var getLocation = function(steps, id) {
    console.log("getLocation()");
    var suc = function(p) {
	initializeMap(p, steps);
    };
    var fail = function() {
	alert("NOT ABLE TO GET THE CURRENT POSITION");
    };
    navigator.geolocation.getCurrentPosition(suc,fail);
}

function initializeMap(p, steps) {
    var gpsstore = new Lawnchair({table: 'mygps', adaptor: 'dom'});
    var destination;
    var to_lat;
    var to_long;
    var fromLatLng;
    var toLatLng;
    var directionsDisplay = new google.maps.DirectionsRenderer();
    var directionsService = new google.maps.DirectionsService();
    var map;
    var result = 0;

    console.log("actual latitude " + p.coords.latitude);
    console.log("actual longitude " + p.coords.longitude);

// Get object of URL parameters
// var allVars = $.getUrlVars();
// console.log("allVars");
// console.log(allVars);

    // Getting URL var by its nam
    var currentId = $.getUrlVar('id');
    
    if(currentId === undefined) {
	console.log("id is undefined, getting default store");
	// retrieve my data from my stores
	gpsstore.get('default', function(r) {
	    if(r !== null) {
		result = 1;
    		console.log(r);
		destination = r.value.name;
		to_lat = r.value.latitude;
		to_long = r.value.longitude;
	    }
	});
    } else {
	if(currentId == 0) currentId = "default";
	console.log("have an id value, getting store " + currentId);
	// retrieve my data from my stores
	gpsstore.get(currentId, function(r) {
    	    console.log(r);
	    destination = r.value.name;
	    to_lat = r.value.latitude;
	    to_long = r.value.longitude;
	});	
    }

    if(!result) {
	console.log("no positions saved, exit...");
	$('.content').append("<div align=\"center\">No saved positions, park your car first!</div>");
	return;
    }

    // gpsstore.get('destination', function(r) {
    //     destination = r.value;<commit_msg>whereis: fix bug, r null in one case<commit_after>// steps = 0 => coming from whereis2.html i.e. not show steps
// steps = 1 => coming from whereis-text.html i.e. show steps
function loader(method, steps) {
    var state = document.readyState;	

    if (typeof(localStorage) == 'undefined' ) {
	alert('Upgrade your browser as it does not support HTML5 localStorage.');
    } 

    if (state == 'loaded' || state == 'complete') {
	method(steps);
    } else {
        if (navigator.userAgent.indexOf('Browzr') > -1) {
	    setTimeout(method(steps), 250);
        } else {
	    document.addEventListener('deviceready',method(steps),false);
	}
    }
}

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

function getLocationFromStore() {
    var gpsstore = new Lawnchair({table: 'mygps', adaptor: 'dom'});
    var destination;
    var to_lat;
    var to_long;
    var result = 0;

    // retrieve my data from my store
    gpsstore.get('default', function(r) {
	if(r !== null) {
	    result = 1;
    	    console.log(r);
	    destination = r.value.name;
	    to_lat = r.value.latitude;
	    to_long = r.value.longitude;
	}
    });

    // gpsstore.get('destination', function(r) {
    //     destination = r.value;
    // });

    if(result) {
	$('.content').append(destination + " (lat: " + to_lat + ", long: " + to_long + ")");
	$('.content').append('<br /><a href="whereis2.html" rel="external">watch on map</a>');
    } else {
	$('.content').append("No saved positions, park your car first!");
    }

}

var getLocation = function(steps, id) {
    console.log("getLocation()");
    var suc = function(p) {
	initializeMap(p, steps);
    };
    var fail = function() {
	alert("NOT ABLE TO GET THE CURRENT POSITION");
    };
    navigator.geolocation.getCurrentPosition(suc,fail);
}

function initializeMap(p, steps) {
    var gpsstore = new Lawnchair({table: 'mygps', adaptor: 'dom'});
    var destination;
    var to_lat;
    var to_long;
    var fromLatLng;
    var toLatLng;
    var directionsDisplay = new google.maps.DirectionsRenderer();
    var directionsService = new google.maps.DirectionsService();
    var map;
    var result = 0;

    console.log("actual latitude " + p.coords.latitude);
    console.log("actual longitude " + p.coords.longitude);

// Get object of URL parameters
// var allVars = $.getUrlVars();
// console.log("allVars");
// console.log(allVars);

    // Getting URL var by its nam
    var currentId = $.getUrlVar('id');
    
    if(currentId === undefined) {
	console.log("id is undefined, getting default store");
	// retrieve my data from my stores
	gpsstore.get('default', function(r) {
	    if(r !== null) {
		result = 1;
    		console.log(r);
		destination = r.value.name;
		to_lat = r.value.latitude;
		to_long = r.value.longitude;
	    }
	});
    } else {
	if(currentId == 0) currentId = "default";
	console.log("have an id value, getting store " + currentId);
	// retrieve my data from my stores
	gpsstore.get(currentId, function(r) {
	    if(r !== null) {
		result = 1;
    		console.log(r);
		destination = r.value.name;
		to_lat = r.value.latitude;
		to_long = r.value.longitude;
	    }
	});	
    }

    if(!result) {
	console.log("no positions saved, exit...");
	$('.content').append("<div align=\"center\">No saved positions, park your car first!</div>");
	return;
    }

    // gpsstore.get('destination', function(r) {
    //     destination = r.value;
{'fraction_non_alphanumeric': 0.16729475100942126, 'fraction_numerical': 0.005248990578734859, 'mean_word_length': 2.944267515923567, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '763768', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2491, 'n_words': 590}