summaryrefslogtreecommitdiff
path: root/public/static/js/geostop.min.js
blob: 25ce8825024420320b9669255d44e33559c3ccfb (plain)
1
$(function(){function t(e){o(),e.error?a("Backend-Fehler:",e.error,null):0==e.candidates.length?a("Keine Stationen in 70km Umkreis gefunden","",null):$.each(e.candidates,function(e,t){var n=t.eva,o=t.name,a=t.distance,t=t.hafas,a=a.toFixed(1),r=$(document.createElement("a")),n=(r.attr("href",n+"?hafas="+t),r.text(o),$(document.createElement("div")));n.attr("class","distance"),n.text(a),r.append(n),$("div.candidatelist").append(r)})}var o=function(){$("div.candidatestatus").remove()},a=function(e,t,n){var o=$(document.createElement("div")),t=(o.attr("class","error"),o.text(t),$(document.createElement("strong")));t.text(e),o.prepend(t),n&&((e=$(document.createElement("div"))).attr("class","errcode"),e.text(n),o.append(e)),$("div.candidatelist").append(o)};navigator.geolocation?(navigator.geolocation.getCurrentPosition(function(e){$.post("/_geolocation",{lon:e.coords.longitude,lat:e.coords.latitude,hafas:window.location.href.match("hafas=1")?1:0},t).fail(function(e,t,n){o(),a("Netzwerkfehler: ",t,n)}),$("div.candidatestatus").text("Suche Stationen…")},function(e){o(),e.code==e.PERMISSION_DENIED?a("Standortanfrage nicht möglich.","Vermutlich fehlen die Rechte im Browser oder der Android Location Service ist deaktiviert.","geolocation.error.PERMISSION_DENIED"):e.code==e.POSITION_UNAVAILABLE?a("Standort konnte nicht ermittelt werden","(Service nicht verfügbar)","geolocation.error.POSITION_UNAVAILABLE"):e.code==e.TIMEOUT?a("Standort konnte nicht ermittelt werden","(Timeout)","geolocation.error.TIMEOUT"):a("Standort konnte nicht ermittelt werden","(unbekannter Fehler)","unknown geolocation.error code")}),$("div.candidatestatus").text("Position wird bestimmt…")):(o(),a("Standortanfragen werden von diesem Browser nicht unterstützt","",null))});