美文网首页
Leancloud 地理位置

Leancloud 地理位置

作者: 点滴回忆 | 来源:发表于2016-05-19 16:21 被阅读194次

LeanCloud地理位置查询:

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

根据AVFeoPoint创建地理位置:

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

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

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

也可以加入限制:

whereWithinKilometers 、 whereWithinMiles 或 whereWithinRadians 方法

eg:

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

相关文章

网友评论

      本文标题:Leancloud 地理位置

      本文链接:https://www.haomeiwen.com/subject/zojgrttx.html