2016-02-09 7 views
5

मैं फ़ायरबेस और इसकी स्थान लाइब्रेरी, जियोफायर के साथ काम करने के लिए काफी नया हूं। वर्तमान में मुझे अपने डेटा की संरचना करते समय कुछ समस्या का सामना करना पड़ रहा है।उपयोगकर्ता स्थान पर GeoFire क्वेरी

फिलहाल मेरी db कुछ इस तरह है:।

users 
    facebook:xxxxx 
    displayName: xx 
    firstName: xx 
    lastName: xx 
    location: 
     g: xxxx 
     l: 
     0: xxx 
     1: xxx 
    facebook:yyyyy 
    displayName: yy 
    firstName: yy 
    lastName: yy 
    location: 
     g: yyyy 
     l: 
     0: yyy 
     1: yyy 

मैं उन कि मेरे वर्तमान में लॉग इन उपयोगकर्ता के पास हैं पर क्वेरी करने के लिए चाहते हैं ऐसा करने के लिए मैं नहीं समझ सकता क्या पथ मैं करने के लिए है उल्लिखित करना।

पल मैं इस तरह कर रहा हूँ पर

(लेकिन वह काम नहीं करता):

let geoFire = GeoFire(firebaseRef: Firebase(url: "myapp.firebaseio.com").childByAppendingPath("users")) 
let query = geoFire.queryAtLocation(currentLocation, withRadius: radius) 

query.observeEventType(GFEventTypeKeyEntered, withBlock: { 
    (key: String!, location: CLLocation!) in 

    print("+ + + + Key '\(key)' entered the search area and is at location '\(location)'") 
    self.userCount++ 
    self.refreshUI() 
}) 
के पास वर्तमान स्थान

let root = Firebase(url: "myapp.firebaseio.com") 
let usersRoot = root.childByAppendingPath("users") 
geoFire = GeoFire(firebaseRef: usersRoot.childByAppendingPath(root.authData.uid)) 

geoFire.setLocation(currentLocation, forKey: "location") { (error) in 
    if (error != nil) { 
     print("An error occured: \(error)") 
    } else { 
     print("Saved location successfully!") 
    } 
} 

अन्य उपयोगकर्ताओं को पुन: प्राप्त बचत


अद्यतन

बचत वर्तमान स्थान

let root = Firebase(url: "myapp.firebaseio.com") 
geoFire = GeoFire(firebaseRef: root.childByAppendingPath("locations")) 

geoFire.setLocation(currentLocation, forKey: root.authData.uid) { (error) in 
    if (error != nil) { 
     print("An error occured: \(error)") 
    } else { 
     print("Saved location successfully!") 
    } 
} 

पुन: प्राप्त करने

let geoFire = GeoFire(firebaseRef: Firebase(url: "myapp.firebaseio.com").childByAppendingPath("locations")) 
let query = geoFire.queryAtLocation(currentLocation, withRadius: radius) 

query.observeEventType(GFEventTypeKeyEntered, withBlock: { 
    (key: String!, location: CLLocation!) in 

    print("+ + + + Key '\(key)' entered the search area and is at location '\(location)'") 
    self.userCount++ 
    self.refreshUI() 
}) 

उत्तर

4

पास अन्य उपयोगकर्ताओं GeoFire के लिए आप पेड़ में एक खंड रखना चाहिए कि सिर्फ जियोलोकेशन और फिर आप शामिल पेड़ में एक और खंड है जिसमें वस्तुओं के बारे में अन्य जानकारी शामिल है।

user_locations 
    uid1: 
    g: xxxx 
    l: 
     0: xxx 
     1: xxx 
    uid2: 
    g: xxxx 
    l: 
     0: xxx 
     1: xxx 
user_profiles: 
    uid1: 
    name: "giacavicchioli" 
    uid2: 
    name: "Frank van Puffelen" 

यह भी देखें: Query firebase data linked to GeoFire

+0

धन्यवाद! मैं अभी कोशिश कर रहा हूं, लेकिन अभी भी काम नहीं कर रहा है। मैं इस तरह की कोशिश की (अपने डाटाबेस संरचना पर विचार): जाने geoFire = GeoFire (firebaseRef: root.childByAppendingPath ("user_locations")) देना क्वेरी = geoFire.queryAtLocation (currentLocation, withRadius: 10) query.observeEventType (GFEventTypeKeyEntered, withlock: { (कुंजी: स्ट्रिंग !, स्थान: CLLocation!) प्रिंट ("+ + + कुंजी '\ (कुंजी)' खोज क्षेत्र में प्रवेश किया गया है और स्थान पर है \ \ (स्थान) ') }) – giacavicchioli

+0

हल किया गया, क्वेरी केंद्र सेट करते समय कोई समस्या हुई। धन्यवाद। – giacavicchioli

+0

फायरबेस Geofire-js: स्थैतिक (निश्चित) स्थानों के नजदीक की चाबियों की सूची कैसे प्राप्त करें: http://stackoverflow.com/questions/43632746/firebase-geofire-js-how-to-get-list-of-keys -of-पास-दर-staticfixed-स्थानों –

1

अपने सभी रिकॉर्ड क्वेरी से मेल खाने आप की तरह कुछ का उपयोग कर के सभी स्टोर करने के लिए है सहेजने के लिए:

var allKeys = [String:CLLocation]() 

    circleQuery.observeEventType(GFEventTypeKeyEntered, withBlock: { 
     (key: String!, location: CLLocation!) in 

     allKeys [key]=location 
     } 

और उसके बाद का उपयोग

circleQuery.observeReadyWithBlock({ 
     print("All initial data has been loaded and events have been fired!") 
    }) 
0

लगता है कि GFEventType सेट अप करते समय कोई समस्या है। यही कारण है कि समाधान हो जाएगा यह GeoFire 1.3 के अगले संस्करण पर लगता है, अब आप यह कर सकते हैं के लिए ...

let geoFire = GeoFire(firebaseRef: ref) 

var allKeys = [String:CLLocation]() 

let query = geoFire.queryAtLocation(coordinates, withRadius: 0.2) 
print("about to query") 
query.observeEventType(GFEventType.init(0), withBlock: {(key: String!, location: CLLocation!) in 
    print("Key: \(key), location \(location.coordinate.latitude)") 
    allKeys [key] = location 
}) 

आप GFEventType.init देख सकते हैं (0) ... कि तीन प्रकार के नक्शे कुछ कारणों से स्विफ्ट में जियोफायर पर सही ढंग से मैप नहीं किए गए एनम्स।

संबंधित मुद्दे