From 4f3c3043d191368e0eda02ce83f461ec84fa9fbe Mon Sep 17 00:00:00 2001
From: Phyks
Date: Thu, 1 Aug 2013 14:19:35 +0200
Subject: [PATCH] Added the ability to search around a specific position
---
index.php | 16 ++++-
js.js | 177 ++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 154 insertions(+), 39 deletions(-)
diff --git a/index.php b/index.php
index d406198..b2c3141 100644
--- a/index.php
+++ b/index.php
@@ -92,7 +92,21 @@
}
?>
-
Votre navigateur doit prendre en charge la géolocalisation pour que ce site puisse fonctionner correctement. Your browser must have geolocation capabilities for this site to display.
+
Map is handled thanks to the Leaflet library, using © OpenStreetMap contributors tiles. Reverse geolocation (Nominatim) are provided by the MapQuest open API. Routes are provided by the OSRM project (OSRM is a free and open source program under GNU Affero GPL).
diff --git a/js.js b/js.js
index 4ea2e02..a0e9d67 100644
--- a/js.js
+++ b/js.js
@@ -2,11 +2,23 @@
var tiles_provider = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png';
var reverse_geolocation_provider = "http://open.mapquestapi.com/nominatim/v1/reverse.php";
var directions_provider = "http://router.project-osrm.org/viaroute";
+var lat_long_provider = "http://open.mapquestapi.com/nominatim/v1/search.php"
var email = "webmaster@phyks.me"; //Mettre votre adresse e-mail ici si vous utilisez Nominatim (cf Usage Policy de Nominatim)
/* Script : */
window.onload = function() {
+ function escapeHTML(unsafe)
+ {
+ return unsafe
+ .replace(/&/g, "&")
+ .replace(//g, ">")
+ .replace(/"/g, """)
+ .replace(/'/g, "'");
+ }
+
+
function params() //Get all the parameters in the URL
{
var t = location.search.substring(1).split('&');
@@ -14,7 +26,7 @@ window.onload = function() {
for (var i=0; iUne erreur a été rencontrée. Veuillez réessayer.
";
+ }
+ else
+ {
+ xhr.onreadystatechange = function()
+ {
+ if(xhr.readyState == 4)
+ {
+ if(xhr.status == 200)
+ {
+ var json = JSON.parse(xhr.responseText); //Parse the response
+
+ latitude = json[0].lat;
+ longitude = json[0].lon;
+
+ if(latitude == 0 && longitude == 0)
+ document.getElementById("position").innerHTML = "Une erreur a été rencontrée. Veuillez réessayer.
";
+ else
+ getBikes(latitude, longitude);
+ }
+ }
+ }
+ }
+
+ xhr.open("GET", lat_long_provider+"?format=json&q="+encodeURI(position+", Paris, France"), true); //xhr handle the data about stations
+ xhr.send();
+ }
}
else
{
- document.getElementById("position").innerHTML = "Votre navigateur doit prendre en charge la géolocalisation pour que ce site puisse fonctionner correctement.
";
+ var input_params = '';
+
+ for(GET in params) //Define hidden input to keep params
+ {
+ if(GET != '')
+ {
+ input_params += " ";
+ }
+ }
+
+ document.getElementById("position").innerHTML = '';
}
}
else //If we didn't choose what to do, display the choices
{
- document.getElementById("position").innerHTML = " ou ";
+ document.getElementById("position").innerHTML = "
ou
Ignorer la géolocalisation
";
}
}