2

I am a newbie in GEE and I am trying to build up an apparently simple widgets combination that allows to center the map around a point whose coordinates are entered by the users into text boxes. I have tried the following code:

var lon = ui.Textbox({
  value: 1.0,
  placeholder: 'Enter longitude here...',
  onChange: function(value) {
    return(value);
  }
});
print(lon);

var lat = ui.Textbox({
   value: 1.0,
  placeholder: 'Enter latitude here...',
  onChange: function(value) {
    return(value);
  }
});
print(lat);

var Lo = ee.Number.parse(lon);
var La = ee.Number.parse(lat);
var button = ui.Button({
  label: 'Go to Location',
  onClick: function() {
    Map.setCenter(Lo,La,1);
  }
});
print(button);

which returns the following error:

Provided center object has invalid values for lat, lon, or zoom. Expected numeric values.

I am afraid that either I am not able to convert the text into number, or I am making a mistake in the structures defining "lon" and "lat"

1 Answer 1

7

I believe this should solve your problem. See comments in the code below.

var lon = ui.Textbox({
  value: 1.0,
  placeholder: 'Enter longitude here...',
  onChange: function(value) {
    // set value with a dedicated method
    lon.setValue(value);
    return(value);
  }
});
print(lon);

var lat = ui.Textbox({
   value: 1.0,
  placeholder: 'Enter latitude here...',
  onChange: function(value) {
    // set value with a dedicated method
    lat.setValue(value);
    return(value);
  }
});
print(lat);


var Lo;
var La;

var button = ui.Button({
  label: 'Go to Location',
  onClick: function() {
    // you don't have to convert it into EE objects since you are
    // working on the client side
    Lo = parseFloat(lon.getValue());
    La = parseFloat(lat.getValue());
    Map.setCenter(Lo, La, 10);
  }
});
print(button);
2
  • `Perfect! tnx! Still I have no clear why I did not need to convert into EE objects and the operational difference between client and server side. I guess/hope I will learn by practicing.
    – Lollo
    Commented Feb 5, 2019 at 9:07
  • I believe this video can help get you started
    – Basile
    Commented Feb 5, 2019 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.