0

I have a function getLocation like this in my map.ts:

let location = this.geocoderService.getLocation(this.callbackPosition);

//Here do I want to wait for the location to use it in the setView method
if (location.length) {
    this.map.setView(location, 14);

    let toast = this.toastCtrl.create({
        message: 'Location was change successfully',
        duration: 3000,
        position: 'bottom',
        closeButtonText: 'OK',
        showCloseButton: true
    });
    toast.present();
}

And in the geoCoderService I have the getLocation method:

getLocation(callback) {
    let position = [
        this.lat,
        this.lng
    ]

    callback(position);
}

But how do I use the callback to return the position so the initializing of the map wait for the position

Sireini
  • 4,142
  • 12
  • 52
  • 91
  • presumably, whatever `this.callbackPosition` function is, is where you'll get the location – Jaromanda X Apr 02 '18 at 01:05
  • Replace last line with `return callback(position);` – Akxe Apr 02 '18 at 01:09
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Aluan Haddad Apr 03 '18 at 00:16

0 Answers0