Query based on geo localisation

#1

I’m trying to query entry based on the geo localisation (Distance from a certain position)

Is there any ways?

#2

Welcome to our community :smile:

The specific code obviously depends on which client SDK you are using but the simple answer is yes!

You first need a GeoPoint as one of the fields in a class. Then when you query the class you can add a nearGeoPoint constraint to a certain point. This will return an array of objects with location fields with a value that is near the point you specified.

For example from the iOS SDK docs:

// Location
let queryGeoPoint = PFGeoPoint(latitude:40.0, longitude:-30.0)
// Create a query for places
var query = PFQuery(className:"PlaceObject")
// Interested in objects with location near queryGeoPoint
query.whereKey("location", nearGeoPoint:userGeoPoint)

// Final list of objects
placesObjects = query.findObjects()

Then you can also limit the results by distance from the point you specify. See the docs for more details.

#3

Just to note, in the future, please post appropriate code level questions such as this on Stack Overflow using the tag parse-platform.

#4

Thanks for you response! sorry for the tags :frowning:

I’m using the JavaScript SDK (NodeJS)

This is an amazing community!!!

Have a nice day!

1 Like
#5

Not a problem. The docs on geo queries for the JS SDK are very similar.

I agree we have a great community here - if you are ever willing/able to pay it forward we love to see new contributors!

1 Like