Make HTML/Javascript Geolocation function more linear

2018-02-02 21:28:33

I'm checking users locations with HTML Geolocation before unlocking the front door. Geolocation takes a few seconds in addition to the time it takes the user to approve it, so currently I have a callback for what to do next.

function getLocationWithCallbacks(callback, error_callback) {


function (position) {

let location = { "latitude": position.coords.latitude, "longitude": position.coords.longitude };



function (error) {

if (error.code === error.PERMISSION_DENIED)





And I call this function like so..

getLocationWithCallbacks(unlock_request, get_location_denied);

However, I'm not sure if there's a more logical way than this. It would be nice if events happened in a more linear fashion like ("pseudo code")...

function getLocation() {


function(position) { return ['success',