java - Parse Swift syntax to Android -
i had trouble trying retrieve user based on search distance, , have received great support community. code boiled down following:
let userlocation = pfgeopoint(latitude: userlatitude, longitude: userlongitude) query.wherekey("location", neargeopoint:userlocation, withinkilometers: 100)
the issue code tailored swift/xcode, , when tried "converting to" android came down to
query.wherewithinkilometers("location", parsegeopoint point, 100);
i not sure if proper way of writing in java (android), , not sure parsegeopoint point.
i have looked https://parse.com/docs/android/api/com/parse/parsegeopoint.html, bit stuck.
if need clarification, let me know. thanks
update: below how store location point of current user parse
@override public void onlocationchanged(location loc) { // todo auto-generated method stub double lati = loc.getlatitude(); double longi = loc.getlongitude(); parseuser currentuser = parseuser.getcurrentuser(); currentuser.saveinbackground(); parsegeopoint point = new parsegeopoint(lati, longi); currentuser.put("location", point); currentuser.saveinbackground(new savecallback() { @override public void done(parseexception e) { setprogressbarindeterminatevisibility(false); if (e == null) { // success! } else { } } });
below how attempt retrieve it, , see if user fall within range
parsequery<parseuser> query = parseuser.getquery(); parsegeopoint point = new parsegeopoint(47, -122); //ideally best if (47, -122) reflected current user location query.wherewithinkilometers("location", point, 100);
i'd recommend reading through this documentation on android sdk's geopoints. basic syntax you.
@override public void onlocationchanged(location loc) { double lati = loc.getlatitude(); double longi = loc.getlongitude(); //user's current location parsegeopoint point = new parsegeopoint(lati, longi); parsequery<parseobject> query = parsequery.getquery("locations"); query.wherewithinkilometers("location", point, 100); query.findinbackground(new findcallback<parseobject>() { ... }); }
Comments
Post a Comment