首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nearSphere需要一个映射操作符

nearSphere需要一个映射操作符
EN

Stack Overflow用户
提问于 2016-01-10 17:56:09
回答 1查看 87关注 0票数 1

//Rahees是Parse.com中的android类,我想从geopoint获得最近位置的列表,g.Rahees类有列名"Locations“。

我希望通过与Rahees类的Location列中列出的地理点进行比较,从g中得到最近的点点的列表。

//*拉希斯类*

代码语言:javascript
复制
@ParseClassName("Rahees")
public class Rahees extends ParseObject {

   public  Rahees()
    {
        super();
    }


    public String getDisplayName() {
        return getString("displayName");
    }
    public void setDisplayName(String value) {

        put("displayName", value);
    }
    public static ParseQuery<Rahees> getQuery() {
        return ParseQuery.getQuery(Rahees.class);
    }

}

主要活动*

代码语言:javascript
复制
public class MainActivity extends AppCompatActivity {
    ParseGeoPoint g;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ParseUser cuser = ParseUser.getCurrentUser();

        Rahees haila = new Rahees();

        haila.setDisplayName("Rahim");

    }


   //button for Logging out of system
    public void logout(View view)
    {
        ParseUser.logOut();
        Intent intent = new Intent(MainActivity.this, SignUp_Login.class);
        startActivity(intent);


    }

//Button for going to Map Masti class, it is this button which triggers to compare the geopoint g with the geopoints in the server


    public void go_to_maps(View view)
    {

        Intent intent = new Intent(MainActivity.this, Map_Masti.class);
        startActivity(intent);
    }
}

*

代码语言:javascript
复制
public class Map_Masti extends FragmentActivity  {
    ParseGeoPoint g;
    private TextView textView;
    private SupportMapFragment mapFragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_masti);

        textView = (TextView)findViewById(R.id.text);
        mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);

//Query to get the geopoint g from server 

        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.getInBackground("ccm3xKMmr4", new GetCallback<ParseUser>() {
            public void done(ParseUser object, ParseException e) {
                if (e == null) {
                    g = (ParseGeoPoint) object.get("user_Location");
                    Log.d("mohit", g + "");

                } else {
                    // something went wrong
                    Log.d("mohit", e + " ");
                }
            }
        });

//查询比较对象"Rahees“中的哪个地理点与列"Locations”中的哪个地理点接近geopoing "g“

代码语言:javascript
复制
 ParseQuery<Rahees> mapQuery1 = Rahees.getQuery();
        mapQuery1.whereWithinKilometers("Locations", g, 6000);
        mapQuery1.setLimit(3);
        mapQuery1.findInBackground(new FindCallback<Rahees>() {
            @Override
            public void done(List<Rahees> objects, ParseException e) {
                // Handle the results
                if (e == null) {//****this is where the exception error comes, it doesn't goes inside if statement**** 
                    for (int i = 0; i < objects.size(); i++) {
                        Log.d("mohit", "2" + objects.get(i).get("Locations"));

                    }
                } else {
                    Log.d("mohit", "" + e);
                }
            }
        });

}
}

下面是我从其他部分得到的错误

01-10 12:27:38.655 4348-4348/?D/error: com.parse.ParseRequest$ParseRequestException:$nearSphere需要一个映射操作符

我能够从Parse中提取g的值,g的日志输出是:ParseGeoPoint40.00000030.000000

请帮帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-11 13:44:44

您应该只在获得第一个查询的结果之后执行第二个查询,因为gnull,直到被回调初始化为止。

更新:

代码语言:javascript
复制
public class Map_Masti extends FragmentActivity {
    ParseGeoPoint g;
    private SupportMapFragment mapFragment;
    private TextView textView;

    private void getG() {
        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.getInBackground("ccm3xKMmr4", new GetCallback<ParseUser>() {
            public void done(ParseUser object, ParseException e) {
                if (e == null) {
                    g = (ParseGeoPoint) object.get("user_Location");
                    Log.d("mohit", g + "");
                    getLocations();

                } else {
                    // something went wrong
                    Log.d("mohit", e + " ");
                }
            }
        });
    }

    private void getLocations() {
        ParseQuery<Rahees> mapQuery1 = Rahees.getQuery();
        mapQuery1.whereWithinKilometers("Locations", g, 6000);
        mapQuery1.setLimit(3);
        mapQuery1.findInBackground(new FindCallback<Rahees>() {
            @Override
            public void done(List<Rahees> objects, ParseException e) {
                // Handle the results
                if (e == null) {//****this is where the exception error comes, it doesn't goes inside if statement****
                    for (int i = 0; i < objects.size(); i++) {
                        Log.d("mohit", "2" + objects.get(i).get("Locations"));

                    }
                } else {
                    Log.d("mohit", "" + e);
                }
            }
        });
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_masti);
        textView = (TextView) findViewById(R.id.text);
        mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
        getG();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34708829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档