Leancloud 地理位置

LeanCloud地理位置查询:

在创建的时候需要将地理位置传进去

根据AVFeoPoint创建地理位置:

、、
AVGeoPoint point = new AVGeoPoint(30.0, -20.0);
AVObject object = new AVObject("PlaceObject");
object.put("location", point);
object.save()

将得到的地理位置传入表中,然后在表中搜索

    AVQuery query = new AVQuery<>("Todo");
    AVGeoPoint point = new AVGeoPoint(39.9, 116.4);
    query.limit(10);
    //获取离我较近的用户
    query.whereNear("whereCreated", point);
    query.findInBackground(new FindCallback() {
        @Override
        public void done(List list, AVException e) {
            List nearbyTodos = list;
            // 离这个位置最近的 10 个 Todo 对象
        }
    });

也可以加入限制:

whereWithinKilometers 、 whereWithinMiles 或 whereWithinRadians 方法

eg:

 query.whereWithinKilometers("whereCreated", point, 2.0);

你可能感兴趣的:(Leancloud 地理位置)