这里我有一个goolemap项目。它有一个按钮..按钮的活动是:GiveDistance ..
这个按钮应该给我存储在数据库中的所有通过点之间的距离。为了找到它们之间的距离,我将它们保存在一个矩阵中。问题是如何从每一行获取值并保存在矩阵中。
public class GiveDistance extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_give_distance);
double [][] matrix = new double[100][100];
matrix[0][0]=0;
Context context = getApplicationContext();
GPSDatabase myDatabase=new GPSDatabase(this);
myDatabase.open();
Cursor cursor=myDatabase.getAllRows();
cursor.moveToFirst();
int i ;
for ( i = 1; i < cursor.getCount(); i++) {
for (int j = 1; j < cursor.getCount(); j++) {
matrix[i][j]=9999;
cursor.moveToNext();
}
}
//fill lat and long from database
cursor.moveToFirst();
i = 0 ;
for (int j = 1; j < cursor.getCount(); j++) {
//here column 1 includes latitude and column 2 includes logitude
matrix[i][j]=matrix[j][i]=cursor.getInt(1);//1
matrix[i][j]=matrix[j][i]=cursor.getInt(2);//1
//String label = cursor.getString(0);
cursor.moveToNext();
//how to get lat and long. from database and save them in matrix[i][j]?
//We want them separate!!!!
}
cursor.close();
//to calc. distance
cursor.moveToFirst();
int k=0 ;int m,j;
for (j = 1, m =1; j < cursor.getCount(); j++) {
for ( i = 0; i < cursor.getCount(); m++) {
distance(matrix[i][j],matrix[m][k]);
}
}