Source

nextrain / resources / public / js / location.coffee

Full commit
$ ->
    success = (position) ->
        console.log(position)
        $('#lat').html(position.coords.latitude)
        $('#lng').html(position.coords.longitude)
        true

    errorhandler = (error) ->
        console.log("Cannot acquire location.")
        switch error.code
            when error.PERMISSION_DENIED then alert "User did not share location data."
            when error.POSITION_UNAVAILABLE then alert "Could not detect current position"
            when error.TIMEOUT then alert "Retrieving position timed out"
            else alert "Unknown error"


    if navigator.geolocation
        navigator.geolocation.getCurrentPosition(success, errorhandler
                                                 {enableHighAccuracy: true})
    else
        alert("Cannot determine your location.")