geofire returns duplicates keys when expanding radius in swift












0















I am trying to implement infinite scrolling by expanding the radius of my GeoFire query by 5kms so I can get the next set of keys. But my GeoFire query is returning duplicates as it is picking up the keys found within the first 5kms in addition to the next 5kms so-on and so-on...



I was under the impression that it should only return the new keys found within the updated radius, have I missed something?



Console output showing duplicate keys found at 10kms then 15kms radius:



enter image description here



My geoQuery:



let geoQuery = GeoFire(firebaseRef: DB_BASE.child("venues-location")).query(at: CLLocation(), withRadius: 1)


My fetchVenueNearby function:



func fetchVenueNearby(deviceLocation: CLLocation, radius: Double, handler: @escaping (Venue) -> ()) {

geoQuery.center = deviceLocation
geoQuery.radius = radius

geoQuery.observe(.keyEntered) { (key: String!, venueLocation: CLLocation!) in

print ("FOUND KEY: ", key)

self.REF_VENUES.child(key).observeSingleEvent(of: .value, with: { (snapshot) in

if let dictionary = snapshot.value as? [String : Any] {

//parse snapshot code here….

}//end if-let

})//end observeSingleEvent

}//end geofire query observe


}//end func


This is my loadMoreVenues func currently used for testing my Geo Query



func loadMoreVenus() {

radius += 5

print("radius = (radius)")


DataService.run.fetchVenueNearby(deviceLocation: currentLocation, radius: radius) { (venue) in
print("venue: (venue.venueID)")
}


}//end func









share|improve this question























  • you need to filter out the already added places

    – Mohmmad S
    Nov 21 '18 at 7:23
















0















I am trying to implement infinite scrolling by expanding the radius of my GeoFire query by 5kms so I can get the next set of keys. But my GeoFire query is returning duplicates as it is picking up the keys found within the first 5kms in addition to the next 5kms so-on and so-on...



I was under the impression that it should only return the new keys found within the updated radius, have I missed something?



Console output showing duplicate keys found at 10kms then 15kms radius:



enter image description here



My geoQuery:



let geoQuery = GeoFire(firebaseRef: DB_BASE.child("venues-location")).query(at: CLLocation(), withRadius: 1)


My fetchVenueNearby function:



func fetchVenueNearby(deviceLocation: CLLocation, radius: Double, handler: @escaping (Venue) -> ()) {

geoQuery.center = deviceLocation
geoQuery.radius = radius

geoQuery.observe(.keyEntered) { (key: String!, venueLocation: CLLocation!) in

print ("FOUND KEY: ", key)

self.REF_VENUES.child(key).observeSingleEvent(of: .value, with: { (snapshot) in

if let dictionary = snapshot.value as? [String : Any] {

//parse snapshot code here….

}//end if-let

})//end observeSingleEvent

}//end geofire query observe


}//end func


This is my loadMoreVenues func currently used for testing my Geo Query



func loadMoreVenus() {

radius += 5

print("radius = (radius)")


DataService.run.fetchVenueNearby(deviceLocation: currentLocation, radius: radius) { (venue) in
print("venue: (venue.venueID)")
}


}//end func









share|improve this question























  • you need to filter out the already added places

    – Mohmmad S
    Nov 21 '18 at 7:23














0












0








0








I am trying to implement infinite scrolling by expanding the radius of my GeoFire query by 5kms so I can get the next set of keys. But my GeoFire query is returning duplicates as it is picking up the keys found within the first 5kms in addition to the next 5kms so-on and so-on...



I was under the impression that it should only return the new keys found within the updated radius, have I missed something?



Console output showing duplicate keys found at 10kms then 15kms radius:



enter image description here



My geoQuery:



let geoQuery = GeoFire(firebaseRef: DB_BASE.child("venues-location")).query(at: CLLocation(), withRadius: 1)


My fetchVenueNearby function:



func fetchVenueNearby(deviceLocation: CLLocation, radius: Double, handler: @escaping (Venue) -> ()) {

geoQuery.center = deviceLocation
geoQuery.radius = radius

geoQuery.observe(.keyEntered) { (key: String!, venueLocation: CLLocation!) in

print ("FOUND KEY: ", key)

self.REF_VENUES.child(key).observeSingleEvent(of: .value, with: { (snapshot) in

if let dictionary = snapshot.value as? [String : Any] {

//parse snapshot code here….

}//end if-let

})//end observeSingleEvent

}//end geofire query observe


}//end func


This is my loadMoreVenues func currently used for testing my Geo Query



func loadMoreVenus() {

radius += 5

print("radius = (radius)")


DataService.run.fetchVenueNearby(deviceLocation: currentLocation, radius: radius) { (venue) in
print("venue: (venue.venueID)")
}


}//end func









share|improve this question














I am trying to implement infinite scrolling by expanding the radius of my GeoFire query by 5kms so I can get the next set of keys. But my GeoFire query is returning duplicates as it is picking up the keys found within the first 5kms in addition to the next 5kms so-on and so-on...



I was under the impression that it should only return the new keys found within the updated radius, have I missed something?



Console output showing duplicate keys found at 10kms then 15kms radius:



enter image description here



My geoQuery:



let geoQuery = GeoFire(firebaseRef: DB_BASE.child("venues-location")).query(at: CLLocation(), withRadius: 1)


My fetchVenueNearby function:



func fetchVenueNearby(deviceLocation: CLLocation, radius: Double, handler: @escaping (Venue) -> ()) {

geoQuery.center = deviceLocation
geoQuery.radius = radius

geoQuery.observe(.keyEntered) { (key: String!, venueLocation: CLLocation!) in

print ("FOUND KEY: ", key)

self.REF_VENUES.child(key).observeSingleEvent(of: .value, with: { (snapshot) in

if let dictionary = snapshot.value as? [String : Any] {

//parse snapshot code here….

}//end if-let

})//end observeSingleEvent

}//end geofire query observe


}//end func


This is my loadMoreVenues func currently used for testing my Geo Query



func loadMoreVenus() {

radius += 5

print("radius = (radius)")


DataService.run.fetchVenueNearby(deviceLocation: currentLocation, radius: radius) { (venue) in
print("venue: (venue.venueID)")
}


}//end func






swift geofire






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 6:54









RoggieRoggie

215213




215213













  • you need to filter out the already added places

    – Mohmmad S
    Nov 21 '18 at 7:23



















  • you need to filter out the already added places

    – Mohmmad S
    Nov 21 '18 at 7:23

















you need to filter out the already added places

– Mohmmad S
Nov 21 '18 at 7:23





you need to filter out the already added places

– Mohmmad S
Nov 21 '18 at 7:23












1 Answer
1






active

oldest

votes


















0














You need to filter out the already existed results.



As you request new result with new parameter that it +5km it's going to return you a new result and you have to compare what already there and remove it from the result.



I don't know alot about GeoFire but however.



A better choice is to request based on the latest place you get as your starting point instead of the user current place to get the latest result without having to deal with filtering them






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406700%2fgeofire-returns-duplicates-keys-when-expanding-radius-in-swift%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You need to filter out the already existed results.



    As you request new result with new parameter that it +5km it's going to return you a new result and you have to compare what already there and remove it from the result.



    I don't know alot about GeoFire but however.



    A better choice is to request based on the latest place you get as your starting point instead of the user current place to get the latest result without having to deal with filtering them






    share|improve this answer




























      0














      You need to filter out the already existed results.



      As you request new result with new parameter that it +5km it's going to return you a new result and you have to compare what already there and remove it from the result.



      I don't know alot about GeoFire but however.



      A better choice is to request based on the latest place you get as your starting point instead of the user current place to get the latest result without having to deal with filtering them






      share|improve this answer


























        0












        0








        0







        You need to filter out the already existed results.



        As you request new result with new parameter that it +5km it's going to return you a new result and you have to compare what already there and remove it from the result.



        I don't know alot about GeoFire but however.



        A better choice is to request based on the latest place you get as your starting point instead of the user current place to get the latest result without having to deal with filtering them






        share|improve this answer













        You need to filter out the already existed results.



        As you request new result with new parameter that it +5km it's going to return you a new result and you have to compare what already there and remove it from the result.



        I don't know alot about GeoFire but however.



        A better choice is to request based on the latest place you get as your starting point instead of the user current place to get the latest result without having to deal with filtering them







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 7:27









        Mohmmad SMohmmad S

        2,0761420




        2,0761420
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406700%2fgeofire-returns-duplicates-keys-when-expanding-radius-in-swift%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()