Oliver Dixon
Oliver Dixon

Reputation: 7405

Firebase query for two values

I'm trying to implement locational based query in Firebase without GeoFire (Since the last update was 6 months ago it seems deprecated)

Anyhow, I can't figure this out.

It's not firing the listener. When there's not starting at or ending at it works.

Query looks like so: (Just testing with Latitude)

// Testing, only doing longtude atm.
        geoFlamesFIRReference
            .queryStarting(atValue: coordinates!.longitude - radius, childKey: "longtitude")
            .queryEnding(atValue: coordinates!.longitude + radius, childKey: "longtitude")
            .queryLimited(toFirst: UInt(Constants.LIMIT_OF_FLAMES_ON_MAP))
            .observe(.value, with: { snapshot in
                print("New location?")
            })

Then example of some of my data:

Firebase geo example not working

Upvotes: 0

Views: 493

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598708

You're using the wrong syntax for querying:

geoFlamesFIRReference
    .queryOrder(byChild: "longtitude")
    .queryStarting(atValue: coordinates!.longitude - radius)
    .queryEnding(atValue: coordinates!.longitude + radius)

Note that you will run into problems when you also want to filter by latitude, as Firebase queries can only contain a single orderBy clause.

GeoFire uses geohashes to work around this limitation. So if you're intent on not using that library, you will have to read up on those.

Upvotes: 1

Related Questions