Question

I have 2 functions and would like to call one function from another and get 2 values.

renderMap: function(){
    // here I need to call getCurrentLocation function and get 2 values - lat and lng from it.
    console.log(lat, lng);
},

getCurrentLocation: function() {
    var me = this,
        lat,
        lng;

    Ext.device.Geolocation.getCurrentPosition({     
        success: function(position) {
            me.lat = position.coords.latitude;
            me.lng = position.coords.longitude;
        }
    });
},

Please advise on how to do this properly.

Was it helpful?

Solution 2

You can return object from getCurrentLocation, for example:

return {lat:xxxx, lng:yyyy};

OTHER TIPS

me doesn't exist anymore when you call Ext.device.Geolocation.getCurrentPosition.

You are in a different context or scope by then, Ext.device.Geolocation class knows nothing about me variable.

At the beginning of your method this refered to your controller, but then you are invoking getCurrentPosition method of Ext.device.Geolocation class, since you are not passing any parameters to the method me should be undefined.

It think you can solve this with Ext.bind

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext-method-bind

Also look for call and apply in JavaScript :)

Best regards @code4jhon

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top