如果未提供回调函数,则以同步方式发出请求。如果提供了回调,则会异步发出请求。
建议使用异步模式,因为同步模式在等待服务器时会停止所有其他代码(例如 EE 代码编辑器界面)。如需发出异步请求,建议使用 evaluate() 而不是 getInfo()。
返回此对象的计算值。
用法 | 返回 |
---|---|
String.getInfo(callback) | 对象 |
参数 | 类型 | 详细信息 |
---|---|---|
此:computedobject | ComputedObject | ComputedObject 实例。 |
callback | 函数(可选) | 可选的回调。如果未提供,则以同步方式进行调用。 |
示例
代码编辑器 (JavaScript)
// After getInfo(), the instance is a local JavaScript string. // Regular JavaScript string manipulations are then available. // // Note: getInfo() fetches results from Earth Engine immediately, and may freeze // the browser or lead to poor performance. Use evaluate() to avoid this. print(ee.String('abc').getInfo().charAt(1)); // b print(ee.String('abc').getInfo()[2]); // c // Using + with ee.String has unexpected results print(ee.String('abc') + 'def'); // ee.String("abc")def // Fetch string using getInfo print(ee.String('abc').getInfo() + 'def'); // abcdef // Improved solution: cat is available on ee.String print(ee.String('abc').cat('def')); // abcdef
import ee import geemap.core as geemap
Colab (Python)
# After getInfo(), the instance is a local Python string. # Regular Python string manipulations are then available. # Note: getInfo() fetches results from Earth Engine synchronously; # later expressions will not be evaluated until it completes. print(ee.String('abc').getInfo()[-2]) # b print(ee.String('abc').getInfo()[2]) # c # Fetch string using getInfo print(ee.String('abc').getInfo() + 'def') # abcdef