// Rahees是Parse.com中用于android的类,我想从335位获取最近位置的列表.Rahees类的列名为“Locations”。
我希望通过将其与Rahees类的位置列中列出的地理位置进行比较来获取g中最近的地理位置列表
// ****************** Rahees班级************************ / /
@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);
}
}
// ************主要活动******************************* //
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);
}
}
// **************************** MapMasti班级*************** ************** //
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”列接近地理位置“g”
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 /错误:com.parse.ParseRequest $ ParseRequestException:$ nearSphere需要一个map运算符
我可以从Parse中检索g的值,log的输出为g是: ParseGeoPoint [40.000000,30.000000]
请帮忙
答案 0 :(得分:0)
您应该在获得第一个查询后才进行第二次查询,因为g
为null
,直到将通过回调进行初始化。
更新
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();
}
}