2016-08-30 6 views
0

私の現在のアプリでは、ユーザーの現在地とユーザーの自宅の住所に基づいて場所のリストを取得しているため、2つの場所が異なります。私はそれらを2つの異なるジオファイヤーツリーに保存し、それらを別々の時間に照会したいと思いますが、結局はそれらを結合したいと思います。だから私のデータはこのように見えるかもしれません。私の質問は、データがロードされた後に2つのデータをどのように組み合わせるかです。私は準備句の外で自分のアクションを実行すると恐れます。私のデータはすべて準備できませんが、もう片方は準備ができていない可能性があります。 ありがとうございました! -currentLocationGeo -user1 -lat:12.345 -lng:53.5435 -addressLocationGeo -user1 -lat:124.544 -lng:34.542つの異なるfirebaseジオクエリをどのようにクエリしますか?

     currentLocationGeo.on("key_entered", function (key, location, distance) { 


         }); 

         addressLocationGeo.on("key_entered", function (key, location, distance) { 


         }); 

         currentLocationGeo.on("ready", function() { 

         }); 

         addressLocationGeo.on("ready", function() { 
          //do something to combine the two geo together and make sure everything is loaded. 
        finalGeo.push(eachLocation); 

         }); 

// finalgeoする何かをするが、私はないですfinalGeoが地理的に準備ができていない状態で実際に準備ができているかどうか確かめてください。

答えて

1

ここで約束をする必要があります。角度のあるものは$q serviceのようです。

$q.allあなたが必要とするものは、すべての約束を完了するのを待っています。しかし、約束がない場合は、2つの遅延オブジェクトを作成して準備コールバックの中で解決し、その$ q.all()を待つことができます。

var currentLocationdeferred = $q.defer(); 
var addressLocationdeferred = $q.defer(); 

currentLocationGeo.on("key_entered", function (key, location, distance) { 
}); 

addressLocationGeo.on("key_entered", function (key, location, distance) { 
}); 

currentLocationGeo.on("ready", function() { 
    currentLocationdeferred.resolve('any result'); 
}); 

addressLocationGeo.on("ready", function() { 
    addressLocationdeferred.resolve('any result 2'); 
}); 

$q.all([currentLocationdeferred.promise, addressLocationdeferred.promise]).then(function(result){ 
    // result[0] == 'any result' 
    // result[1] == 'any result 2' 
    finalGeo.push(eachLocation); 
}) 
関連する問題