如何进行回调以获得当前位置

时间:2018-04-02 00:56:47

标签: javascript typescript callback

我在map.ts中有一个像这样的函数getLocation:

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();
}

在geoCoderService中我有getLocation方法:

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

    callback(position);
}

但是如何使用回调来返回位置,以便初始化地图等待位置

0 个答案:

没有答案