
function getLocation() {
    return new Promise(function(resolve, reject) {
        if ("geolocation" in window.navigator) {
            navigator.geolocation.getCurrentPosition(function(coords) {
                if (coords)
                    resolve(coords);
                else
                    reject("denied");
            });
        } else {
            reject("geolocation not available");
        }
    });
};

onLangInitialized.push(function() {
    CLIENT_COMMANDS.registerCommand({
        name: "/sherlock",
        names: [ "/sherlock", "/sharelock" ],
        usage: "",
        description: locale.shareYourLocation,
        exec: function(context, room, args) {
            getLocation().
                then(function(coords) {
                    var lat = coords["coords"]["latitude"],
                        lon = coords["coords"]["longitude"],
                        acc = coords["coords"]["accuracy"];
                    sendMsg(room, "https://www.openstreetmap.org/?mlat=" +lat +"&mlon=" +lon +"&macc=" +acc +"#map=17/" +lat +'/' +lon);
                }).catch(function(err) {
                    //FIXME maci
                    console.error("Error: ", err);
                });
        }
    });
});

