If the user gives a latitude/longitude/maxDistance, they are used instead of geolocation

This commit is contained in:
mossroy 2014-03-07 15:05:45 +01:00
parent 0a1c5ecdeb
commit c03501c4b0
3 changed files with 1774 additions and 1764 deletions

View File

@ -74,8 +74,8 @@
</span>
</div>
or <a href="#" id="btnArticlesNearby">Find articles around me (work in progress)</a><br/>
Longitude/Latitude:
<input type="text" id="longitude" size="8" /> <input type="text" id="latitude" size="8" /><br/>
Longitude/Latitude/MaxDistance:
<input type="text" id="longitude" size="8" /> <input type="text" id="latitude" size="8" /> <input type="text" id="maxDistance" size="8" /><br/>
or <a href="#" id="btnRandomArticle">Go to a random article</a><br/>
<div id="searchingForTitles" style="position: relative; z-index: 10; top: 20px; height: 0px; display: none;">
<img src="img/spinner.gif" alt="Please wait..." />

View File

@ -539,46 +539,56 @@ define(function(require) {
$('#configuration').hide();
$('#articleContent').empty();
if (localArchive !== null && localArchive.titleFile !== null) {
//var rectangle = new geometry.rect(0,40,10,10);
//localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
if (navigator.geolocation) {
var geo_options = {
enableHighAccuracy: false,
maximumAge: 1800000, // 30 minutes
timeout : 10000 // 10 seconds
};
var longitude = $('#longitude').val();
var latitude = $('#latitude').val();
var maxDistance = $('#maxDistance').val();
if (!maxDistance) {
maxDistance = MAX_DISTANCE_ARTICLES_NEARBY;
}
if (!longitude || !latitude) {
// If the user did not give any latitude/longitude, we try to use geolocation
if (navigator.geolocation) {
var geo_options = {
enableHighAccuracy: false,
maximumAge: 1800000, // 30 minutes
timeout: 10000 // 10 seconds
};
function geo_success(pos) {
var crd = pos.coords;
function geo_success(pos) {
var crd = pos.coords;
var rectangle = new geometry.rect(
crd.longitude - MAX_DISTANCE_ARTICLES_NEARBY,
crd.latitude - MAX_DISTANCE_ARTICLES_NEARBY,
MAX_DISTANCE_ARTICLES_NEARBY * 2,
MAX_DISTANCE_ARTICLES_NEARBY * 2);
alert("Found your location : latitude=" + crd.latitude + ", longitude=" + crd.longitude);
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
};
var rectangle = new geometry.rect(
crd.longitude - maxDistance,
crd.latitude - maxDistance,
maxDistance * 2,
maxDistance * 2);
function geo_error(err) {
alert("Unable to geolocate your device : " + err.code + " : " + err.message);
};
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
};
// TODO : for testing purpose
//navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
var longitude = $('#longitude').val();
var latitude = $('#latitude').val();
function geo_error(err) {
alert("Unable to geolocate your device : " + err.code + " : " + err.message);
};
navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
}
else {
alert("Geolocation is not supported (or disabled) on your device, or on your browser");
}
}
else {
// The user gave a latitude/longitude : let's use it to find articles around that location
var rectangle = new geometry.rect(
longitude - MAX_DISTANCE_ARTICLES_NEARBY,
latitude - MAX_DISTANCE_ARTICLES_NEARBY,
MAX_DISTANCE_ARTICLES_NEARBY * 2,
MAX_DISTANCE_ARTICLES_NEARBY * 2);
longitude - maxDistance,
latitude - maxDistance,
maxDistance * 2,
maxDistance * 2);
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
}
else {
alert("Geolocation is not supported (or disabled) on your device, or by your browser");
}
} else {
$('#searchingForTitles').hide();
// We have to remove the focus from the search field,

View File

@ -790,7 +790,7 @@ define(function(require) {
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos3, targetRect, rectNE, maxTitles, titlePositionsFound, callbackFunction, callbackGetTitlesInCoordsInt);
}
// TODO : it seems possible that targetRect does not intersect any of the 4 rectangles
// Iis it normal? In this case, the callback is never called
// Is it normal? In this case, the callback is never called
}
else {
// This is a leaf node : let's see if its articles are in the