将Swift语法解析为Android

时间:2014-09-22 04:51:55

标签: java android xcode swift parse-platform

我在尝试根据搜索距离检索用户时遇到了麻烦,并得到了该社区的大力支持。代码归结为以下内容:

let userLocation = PFGeoPoint(latitude: userLatitude, longitude: userLongitude)
query.whereKey("location", nearGeoPoint:userLocation, withinKilometers: 100)

问题是代码是针对swift / xcode量身定制的,当我尝试将其转换为" android它归结为

query.whereWithinKilometers("location", ParseGeoPoint point, 100);

我不确定这是否是用Java(android)编写它的正确方法,并且不确定ParseGeoPoint指向该做什么。

我调查了https://parse.com/docs/android/api/com/parse/ParseGeoPoint.html,但有点卡住了。

如果您需要任何澄清,请告诉我。 感谢

更新: 下面是我如何将当前用户的位置点存储到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 {

                    }
                }
            });

以下是我尝试检索它的方法,并查看是否属于范围内的用户

  ParseQuery<ParseUser> query = ParseUser.getQuery();

        ParseGeoPoint point = new ParseGeoPoint(47, -122); //Ideally it would be best if (47, -122) reflected the current user location
        query.whereWithinKilometers("location", point, 100);

1 个答案:

答案 0 :(得分:2)

我建议您阅读this以获取有关Android SDK GeoPoints的文档。这将是您的基本语法。

@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>() { ... });
    }