geofire returns duplicates keys when expanding radius in swift
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:
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
add a comment |
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:
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
you need to filter out the already added places
– Mohmmad S
Nov 21 '18 at 7:23
add a comment |
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:
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
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:
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
swift geofire
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 21 '18 at 7:27
Mohmmad SMohmmad S
2,0761420
2,0761420
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
you need to filter out the already added places
– Mohmmad S
Nov 21 '18 at 7:23