Could not find symbol 'method'

Hye everyone

so i'm trying to get weather in a widget but I have this error everytime,

I use the same code as my watchface (which one work perfectly)

but not on my widget.

here is the code, please let me know whaat it is.

Many thanks

function makeRequest(lat, lng,apiKey) {
var UNITS=(Sys.getDeviceSettings().temperatureUnits==Sys.UNIT_STATUTE) ? "imperial" : "metric";
var url ="">api.openweathermap.org/.../weather";
var param={
"lat" => lat,
"lon"=>lng,
"appid"=>apiKey,
"units" => UNITS};
var options = {
:methods => Communications.HTTP_REQUEST_METHOD_GET,
:headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
};


Communications.makeWebRequest(
url,
param,
options,
method(:receiveWeather));

}

  • The method method is a member of Toybox.Lang.Object. In order to use it you need to call it on an object instance of a class that inherits (explicitly or implicitly) from that class. When you write method(:receiveWeather) that is equivalent to writing self.method(:receiveWeather) but if there is no self, it can't work.


    Developers typically don't realize this and they try to use method from within a function defined at module (or global) scope. 
    For this to work, you could move your function into a class, or you could explicitly create the Lang.Method object like so:

    // i'm assuming that receiveWeather is a function defined at global scope
    var callable = new Lang.Method($, :receiveWeather);

  • thank you very much for your explanation! I get it!

    I put the exemple in case someone wants to see it.

    function makeRequest(lat, lng,apiKey) {
    var UNITS=(Sys.getDeviceSettings().temperatureUnits==Sys.UNIT_STATUTE) ? "imperial" : "metric";
    var url ="">api.openweathermap.org/.../weather";
    var param={
    "lat" => lat,
    "lon"=>lng,
    "appid"=>apiKey,
    "units" => UNITS};
    var options = {
    :methods => Communications.HTTP_REQUEST_METHOD_GET,
    :headers => {"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED},
    :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };
    
    var callable = new Lang.Method($, :receiveWeather);
    Communications.makeWebRequest(
    url,
    param,
    options,
    callable);
    
    }