1
0

sherlock.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. function getLocation() {
  2. return new Promise(function(resolve, reject) {
  3. if ("geolocation" in window.navigator) {
  4. navigator.geolocation.getCurrentPosition(function(coords) {
  5. if (coords)
  6. resolve(coords);
  7. else
  8. reject("denied");
  9. });
  10. } else {
  11. reject("geolocation not available");
  12. }
  13. });
  14. };
  15. onLangInitialized.push(function() {
  16. CLIENT_COMMANDS.registerCommand({
  17. name: "/sherlock",
  18. names: [ "/sherlock", "/sharelock" ],
  19. usage: "",
  20. description: locale.shareYourLocation,
  21. exec: function(context, room, args) {
  22. getLocation().
  23. then(function(coords) {
  24. var lat = coords["coords"]["latitude"],
  25. lon = coords["coords"]["longitude"],
  26. acc = coords["coords"]["accuracy"];
  27. sendMsg(room, "https://www.openstreetmap.org/?mlat=" +lat +"&mlon=" +lon +"&macc=" +acc +"#map=17/" +lat +'/' +lon);
  28. }).catch(function(err) {
  29. //FIXME maci
  30. console.error("Error: ", err);
  31. });
  32. }
  33. });
  34. });