0
votes

I am able to retrieve user latitude and longitude, and hence have their location coordinate through GPS. For instance lets say I have latitude 67, and longitude -25, and lets say I wanted limit the search to 100km, would it be like +- 20 current latitude, and +- 10 current longitude?

If you need any clarification, let me know. Thanks in advance

1
That's more of a math question than a programming one.Xaver Kapeller
Converting decimal degrees coords to kilometers is not constant, I suggest using JTS to perform a buffer operation, or store your data in something like PostGIS so you can store it as geometry and perform spatial queries... depending on your goalmarkgiaconia
Thanks for your responses. The user latitude and longitude information is recorded directly into Parse so I have that information. I agree this is more of a mathematical question.code_legend
How about if I wanted to calculate the distance between two points if the distance falls within that specified range, than it would execute?code_legend

1 Answers

1
votes

Parse makes this very easy. They have built in function called: withinKilometers:, withinMiles:, and withinRadians:. The following query parameter will return all the rows where "location" is within 100 kilometers of the user's current location. Since you've already calculated the user's latitude and longitude, you can create a PFGeoPoint using those values.

Swift Syntax

let userLocation = PFGeoPoint(latitude: userLatitude, longitude: userLongitude)
query.whereKey("location", nearGeoPoint:userLocation, withinKilometers: 100)