How to pass parameters to getCurrentPosition success call back?

后端 未结 2 1188
天涯浪人
天涯浪人 2021-02-20 15:01

How can I pass in one or more parameters to a success call back when calling navigator.geolocation.getcurrentPosition?

How can I pass deviceready

2条回答
  •  旧时难觅i
    2021-02-20 15:48

    Wrap the geolocation callback in function(position) {} as follows. Then you can add as many arguments as you want to your actual callback function.

    var app = {
    
        getGeoLoc : function (id) {
    
            var self = this;
    
            navigator.geolocation.getCurrentPosition(function(position) {
    
                var myVar1, myVar2, myVar3; // Define has many variables as you want here
    
                // From here you can pass the position, as well as any other arguments 
                // you might need. 
                self.foundLoc(position, self, myVar1, myVar2, myVar3)
    
            }, this.noloc, { timeout : 3});
        },
    
        foundLoc : function(position, self, myVar1, myVar2, myVar3) {},
    };
    

    Hope this helps anyone else who might stumble upon this.

提交回复
热议问题