从parse.com检索和使用用户信息

时间:2015-09-24 09:23:07

标签: android google-maps parse-platform

在我的Android应用程序中,我将位置从currentUser放入parse.com的表中。我无法以正确的方式再次检索该信息。

我想为每个对象创建一个for,对于每个对象,我使用用户名和纬度和经度。

我已经阅读了几个小时的API,但是列表是我的弱点,我无法绕过它。

ParseQuery<ParseObject> users  = ParseQuery.getQuery("user");

ParseObject object = (ParseObject) users.get(user); //This is invald, but dno what to write in "get"

final String objectId = users.getObjectId();
final int olat = users.getInt("lat");
final int olong = users.getInt("lng");
String name = users.getString("username");

我希望在每个循环中使用此信息,然后为每个用户添加最后已知纬度和经度的标记;

我有这个我想放入循环;

double oldLatitude = olat;
double oldLongitutde = olong;
LatLng latLng = new LatLng(oldLatitude, oldLongitutde);
MarkerOptions options = new MarkerOptions()
   .position(latLng)
  .title(objectId + "was here!");
mMap.addMarker(options);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 

我有类似的东西,但不知道如何处理它;

public void handleDiffUsers(Location location){



    users.getInBackground(objectId, new GetCallback<ParseObject>() {
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                 for (int i = 0; i < object.size(); i++) {
                      //marker code.. ? 
            } else {
                // something went wrong
            }
        }
    });

1 个答案:

答案 0 :(得分:3)

Retrive ParseUser list并获取ParseGeoPoint

ParseQuery<ParseUser> queryParseUser = ParseUser.getQuery();
        queryParseUser.findInBackground(new FindCallback<ParseUser>() {

        @Override
        public void done(List<ParseUser> locationList, ParseException arg1) {
            // TODO Auto-generated method stub

                    if (locationList != null) {
                        for (ParseUser parseObject : locationList) {
                            ParseGeoPoint parseGeoPoint = parseObject.getParseGeoPoint("location"); "location" is column name of user table
                            // create marker

                            MarkerOptions marker = new MarkerOptions().position(
                                    new LatLng(parseGeoPoint.getLatitude(), parseGeoPoint.getLongitude())).title(parseObject.getUsername());


                            // Changing marker icon
                            marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher));

                            // adding marker
                            googleMap.addMarker(marker);

                        }
                    }

        }
    });