Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jonathan Etienne
24,572 PointsRetrieving users that falls within a range
Hello everyone,
I am trying to retrieve the list of users who fall within their desired range through the back-end system called Parse. In the sense, that when creating a profile users decide through a seekbar to view only users within lets say 50km, and that number is recorded under the Maximum_Distance column on parse.
To achieve this below is what I am trying to do whereWithinKilometers("Maximum_Distance", ParseGeoPoint point, double maxDistance);
Where Maximum_Distance refers to the Maximum_Distance column on parse (where all of the users maximum distance number is recorded): Number maxDistance = ParseUser.getCurrentUser().getNumber( "Maximum_Distance");
In other words, it is retrieving the list of users that falls within the range of the current user Maximum_Distance.
My problem is resolving ParseGeoPoint point. I am not sure how to work around it, where yes even though it knows users maximum distance, and current user maximum distance, but for that to be effective it would to know the location of the current user in respect to the location of all of the users on the list to be able to determine if they fall within range. I do not want to ask users when creating their profile their location because people move around and that could change rapidly, and it would be a hassle to continuously update your location point. One solution would be that point would work with GPS. In the sense whenever the user uses the application its point would be automatically updated, however, that too I am not too sure how to work around.
I have been struggling with this issue since a while, and hence any assistance would be greatly appreciated.
Thanks in advance.
Edit:
I have begun working on the point but is not sure if I am taking the right approach, or could receive some assistance in completing it:
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
ParseGeoPoint point = new ParseGeoPoint(lat, lng);
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}};
1 Answer
Doug Ray
7,493 PointsHey Jonathan,
Sounds like an awesome addition to working with parse. So I would have to agree with your approach you would need to get the users current location whenever you needed to use this max distance functionality. It looks like you have it set up correctly when the users position changes get the ParseGeoPoint. Remember that you need to place the new GeoPoint into your parse data so it can then be queried.
Hope this helps
Doug =D