How to make a Geo-Aware website?
I’ve made a page that locates your closest bank branch using a Geo-aware webpage see
http://www.listofbanks.info/FindBank.aspx
Once you share your location with the page, using the prompt provided, it makes an AJAX call with your longitude and latitude to another page which returns the top 10 banks in our database ordered by distance. The system will only work in europe, so americans may see their nearest bank in spain!.
The JavaScript I used was as follows:
if (geo_position_js.init()) {
geo_position_js.getCurrentPosition(success_callback, error_callback, { enableHighAccuracy: true });
}
else {
window.document.getElementById(“response”).innerHTML = “Failed.”;
}function success_callback(p) {
var oXHR = new XMLHttpRequest();
var strUrl = “FindBankAjax.aspx?”;
strUrl += “Latitude=” + p.coords.latitude.toFixed(2);
strUrl += “&Longitude=” + p.coords.longitude.toFixed(2);
oXHR.open(“get”, strUrl, false);
oXHR.send(null);
window.document.getElementById(“response”).innerHTML = oXHR.responseText;
}function error_callback(p) {
window.document.getElementById(“Failed due to ” + p.code)}