mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-24 04:54:51 -04:00
If the user gives a latitude/longitude/maxDistance, they are used instead of geolocation
This commit is contained in:
parent
0a1c5ecdeb
commit
c03501c4b0
@ -74,8 +74,8 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
or <a href="#" id="btnArticlesNearby">Find articles around me (work in progress)</a><br/>
|
or <a href="#" id="btnArticlesNearby">Find articles around me (work in progress)</a><br/>
|
||||||
Longitude/Latitude:
|
Longitude/Latitude/MaxDistance:
|
||||||
<input type="text" id="longitude" size="8" /> <input type="text" id="latitude" size="8" /><br/>
|
<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/>
|
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;">
|
<div id="searchingForTitles" style="position: relative; z-index: 10; top: 20px; height: 0px; display: none;">
|
||||||
<img src="img/spinner.gif" alt="Please wait..." />
|
<img src="img/spinner.gif" alt="Please wait..." />
|
||||||
|
@ -539,23 +539,31 @@ define(function(require) {
|
|||||||
$('#configuration').hide();
|
$('#configuration').hide();
|
||||||
$('#articleContent').empty();
|
$('#articleContent').empty();
|
||||||
if (localArchive !== null && localArchive.titleFile !== null) {
|
if (localArchive !== null && localArchive.titleFile !== null) {
|
||||||
//var rectangle = new geometry.rect(0,40,10,10);
|
var longitude = $('#longitude').val();
|
||||||
//localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
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) {
|
if (navigator.geolocation) {
|
||||||
var geo_options = {
|
var geo_options = {
|
||||||
enableHighAccuracy: false,
|
enableHighAccuracy: false,
|
||||||
maximumAge: 1800000, // 30 minutes
|
maximumAge: 1800000, // 30 minutes
|
||||||
timeout : 10000 // 10 seconds
|
timeout: 10000 // 10 seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
function geo_success(pos) {
|
function geo_success(pos) {
|
||||||
var crd = pos.coords;
|
var crd = pos.coords;
|
||||||
|
|
||||||
|
alert("Found your location : latitude=" + crd.latitude + ", longitude=" + crd.longitude);
|
||||||
|
|
||||||
var rectangle = new geometry.rect(
|
var rectangle = new geometry.rect(
|
||||||
crd.longitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
crd.longitude - maxDistance,
|
||||||
crd.latitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
crd.latitude - maxDistance,
|
||||||
MAX_DISTANCE_ARTICLES_NEARBY * 2,
|
maxDistance * 2,
|
||||||
MAX_DISTANCE_ARTICLES_NEARBY * 2);
|
maxDistance * 2);
|
||||||
|
|
||||||
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
||||||
};
|
};
|
||||||
@ -564,21 +572,23 @@ define(function(require) {
|
|||||||
alert("Unable to geolocate your device : " + err.code + " : " + err.message);
|
alert("Unable to geolocate your device : " + err.code + " : " + err.message);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO : for testing purpose
|
navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
|
||||||
//navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
|
}
|
||||||
var longitude = $('#longitude').val();
|
else {
|
||||||
var latitude = $('#latitude').val();
|
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(
|
var rectangle = new geometry.rect(
|
||||||
longitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
longitude - maxDistance,
|
||||||
latitude - MAX_DISTANCE_ARTICLES_NEARBY,
|
latitude - maxDistance,
|
||||||
MAX_DISTANCE_ARTICLES_NEARBY * 2,
|
maxDistance * 2,
|
||||||
MAX_DISTANCE_ARTICLES_NEARBY * 2);
|
maxDistance * 2);
|
||||||
|
|
||||||
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
localArchive.getTitlesInCoords(rectangle, MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
alert("Geolocation is not supported (or disabled) on your device, or by your browser");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$('#searchingForTitles').hide();
|
$('#searchingForTitles').hide();
|
||||||
// We have to remove the focus from the search field,
|
// We have to remove the focus from the search field,
|
||||||
|
@ -790,7 +790,7 @@ define(function(require) {
|
|||||||
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos3, targetRect, rectNE, maxTitles, titlePositionsFound, callbackFunction, callbackGetTitlesInCoordsInt);
|
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
|
// 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 {
|
else {
|
||||||
// This is a leaf node : let's see if its articles are in the
|
// This is a leaf node : let's see if its articles are in the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user