我正在构建一个应用,根据用户当前Parse
,使用GeoPoint
从location
云返回图片。
我需要帮助,如何获取用户的当前位置,并根据他们定义的半径,我可以查询来自Parse
Cloud的图像。
protected Void doInBackground(Void... params) {
// Create the array
worldpopulationlist = new ArrayList<PlaceFilter>();
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"geo_filters");
// Locate the column named "ranknum" in Parse.com and order list
// by ascending
for (ParseObject PlaceName : ob) {
// Locate images in flag column
ParseFile image = (ParseFile) PlaceName.get("FilterFile");
PlaceFilter map = new PlaceFilter();
map.setPlaceName((String) PlaceName.get("PlaceName"));
map.setFilterFile(image.getUrl());
worldpopulationlist.add(map);
}
return null;
}
答案 0 :(得分:0)
尝试激情
ParseQuery<ParseObject> parseQuery = ParseQuery.getQuery("ImageClassName");
Location location = getLastKnownLocation(); //You have to get last known location using LOcationManager or FusedLocation API
double latitude = location.getLatitude();
double longitude = location.getLongitude();
userLocation = new ParseGeoPoint(latitude, longitude);
parseQuery.whereNear("location", userLocation); //column as location
parseQuery.whereWithinKilometers("location", userLocation, 5);
parseQuery.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseObject> listImages,
ParseException arg1) {
for(image : listImages){
ParseFile parseFile = image.getParseFile("imageColumn");
if (parseFile != null) {
parseFile.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
// TODO Auto-generated method stub
if (data != null && e == null) {
Bitmap bitmap = BitmapFactory
.decodeByteArray(data, 0,
data.length);
myImage.setImageBitmap(bitmap);
} else {
/picture_not_available
}
}
});
} else {
// picture_not_available
}
}
// TODO Auto-generated method stub
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});