[英]Infinity loop. Reading data from database and comparing them to with an if statment
My English is a little rusty, but I will try to explain what I want to do. 我的英语有些生锈,但是我会尽力解释我想做什么。
I have a database and 5 rows in it. 我有一个数据库和5行。 I am trying to do something like this: 我正在尝试做这样的事情:
if(((szerokosc<=a)&&(szerokosc>=b)) && ((dlugosc>=c)&&(dlugosc<=d)))
I want to do this over and over again; 我想一遍又一遍地做。
public void onLocationChanged(Location location)
{
showLocation(location);
showAdditionalInfo(location);
if(savedLocation == null)
savedLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
DataBaseHelper zb = new DataBaseHelper(getApplicationContext());
double szerokosc = location.getLatitude();
double dlugosc = location.getLongitude();
Cursor k = zb.dajCos();
String lokalizacja = "Jestes na: ";
while(k.moveToNext())
{
nazwa = k.getString(0);
szmax= k.getDouble(1);
szmin= k.getDouble(2);
dlmin= k.getDouble(3);
dlmax= k.getDouble(4);
opis = k.getString(5);
a=szmax;
b=szmin;
c=dlmin;
d=dlmax;
if(k.moveToNext()==false){k.moveToFirst();}
}
if(((szerokosc<=a)&&(szerokosc>=b)) && ((dlugosc>=c)&&(dlugosc<=d)))
{
lokalizacja =nazwa+opis;
}
else
{
lokalizacja ="brak danych";
}
tvLokalizacja.setText(lokalizacja);
}
This is public Cursor dajCos()
这是公共Cursor dajCos()
public Cursor dajCos()
{
String[] kolumny={"nazwa","szmax","szmin","dlmin","dlmax","opis"};
SQLiteDatabase db = getReadableDatabase();
Cursor kursor = db.query("obiekty", kolumny, null, null, null, null, null);
return kursor;
}
I dont know how to explain this better. 我不知道如何更好地解释这一点。 I will try to describe this in that way. 我将尝试以这种方式进行描述。
In database I have 5 records each of them include coordinates. 在数据库中,我有5条记录,每个记录都包含坐标。 For example: My position corresponds to coordinates from second row , I want to display you are in "zone1", I move ten meters away and my position don't match to coordinates in any row so I want to display "no data", I move fifteen meters away then fourth row coordinates match to my position and display you are in "zone2". 例如:我的位置对应于第二行的坐标,我想显示您在“ zone1”中,我移动了十米,而我的位置与任何行中的坐标都不匹配,因此我想显示“无数据”,我移动了15米,然后第四行坐标与我的位置匹配,并显示您在“ zone2”中。
I hope you will understand what I mean and help me. 希望您能理解我的意思并帮助我。 Thank you. 谢谢。
I have this loop: 我有这个循环:
k.moveToFirst(); //iterate over rows for (int i = 0; i < k.getCount(); i++) { nazwa = k.getString(0); szmax= k.getDouble(1); szmin= k.getDouble(2); dlmin= k.getDouble(3); dlmax= k.getDouble(4); opis = k.getString(5); a=szmax; b=szmin; c=dlmin; d=dlmax; wypisz +=i+nazwa+"-"+a+"-"+opis+"\\n"; tvBaza.setText(wypisz); k.moveToNext(); }
the loop execute 5 times because I have 5 rows in database. 该循环执行5次,因为我在数据库中有5行。 I want to change it to execute over and over again. 我想更改它以反复执行。
Could You give me a clue. 你能给我一个线索吗? I don't know how to explain this. 我不知道该怎么解释。 My database have 5 rows. 我的数据库有5行。 They looks like that: 它们看起来像这样:
1 Zone_A(nazwa), 50.03233693(dlmax), 50.0281259(dlmin), 22.00383871(szmin), 22.0094177(szmax), You are in zone_A(opis). 1 Zone_A(nazwa),50.03233693(dlmax),50.0281259(dlmin),22.00383871(szmin),22.0094177(szmax),您在zone_A(opis)中。
As You see I have coordinates and names in them. 如您所见,我在其中包含坐标和名称。 My goal is to achieve somethin like that. 我的目标是实现这样的目标。
When my location change I get in to database check each row, if coordinates from one of them mach to the statement 当我的位置更改时,我进入数据库检查每一行,是否从其中之一坐标到语句
if(((szerokosc<=a)&&(szerokosc>=b)) && ((dlugosc>=c)&& (dlugosc<=d)))`
where 哪里
a=szmax;b=szmin;c=dlmin;d=dlmax;
and 和
double szerokosc = location.getLatitude();
double dlugosc = location.getLongitude();
if they match display (nazwa+opis) if not dispaly(brak danych). 如果它们匹配显示(nazwa + opis),则不显示(brak danych)。 When I am moving then data in 当我移动时,输入数据
double szerokosc = location.getLatitude();
double dlugosc = location.getLongitude();
are changing too. 也在改变。
So I have to get in to database againg to check if one of row fits to new coordinates obtained from GPS which are saved in 所以我必须再次进入数据库g来检查行中是否有一个适合从GPS获取的新坐标,并保存在
double szerokosc = location.getLatitude();
double dlugosc = location.getLongitude();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.