1

I'm working in Google Earth Engine and I want to access the user's location to then be able to use the position when visualizing data layers. When running the code below, GEE doesn't seem to be able to understand the navigator which contains the geolocation info I'm looking for. Same goes for document. This makes me wonder whether GEE even works in JS since it doesn't understand the queries(?) Anyone with a solution to access the user location?

var locationButton = ui.Button('User location');
locationButton.onClick(function() {

  var startPos;
  var geoSuccess = function(position) {
    startPos = position;
    document.getElementById('startLat').innerHTML = startPos.coords.latitude;
    document.getElementById('startLon').innerHTML = startPos.coords.longitude;
     if (navigator.geolocation) {
      console.log('Geolocation is supported!');
    }
    else {
      console.log('Geolocation is not supported for this Browser/OS.');
    }
  };
  navigator.geolocation.getCurrentPosition(geoSuccess);

});
Map.add(locationButton);
  • as per the answer to this question gis.stackexchange.com/questions/307963/… GEE doesn't run in your browser's JavaScript, but in a sandboxed JS system. I asked and I didn't get any answer as to what are the specifications of this JS system and whether it complies to any standard. The conclusion is that some JS features are just disabled and that's that. I can't put this as an answer as I'm not sure yet that it's true, but I am afraid the answer for you is that it's just not possible currently. – Andrei Mar 10 at 15:23
  • 1
    Thank you @Andrei for your clarification. I solved the issue by letting the user choose their location of interest by clicking in the map using onClick – Felix Althén Bergman Mar 12 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.