views:

403

answers:

1

Hello,

I am trying to calculate the distance between the first GPS point stored in a SQLite database and the last GPs point stored.

My code so far is this:

private double Distance() 
{

SQLiteDatabase db1 = waypoints.getWritableDatabase();
Cursor cursor = db1.query(TABLE_NAME, FROM, null, null, null, null,ORDER_BY);
Cursor cursor1 = db1.query(TABLE_NAME, FROM, null, null, null, null,ORDER_BY);
Double lat = cursor.getDouble(2);
Double lon = cursor.getDouble(1);
cursor.moveToFirst();
cursor.moveToLast();
cursor.close();
distance = cursor.distanceTo(cursor1);

}

I realise I need to return a value but the error I am receiving is for the distanceTo method

"The method distanceTo(Cursor) is undefined for the type Cursor"

Thanks.

+2  A: 

As the error message says, the method distanceTo() doesn't exist on the type Cursor: http://developer.android.com/intl/zh-CN/reference/android/database/Cursor.html

The method distanceTo(Location) is available on the Location class: http://developer.android.com/intl/zh-CN/reference/android/location/Location.html

You'll need to create Location objects from your longitude/latitude values in your DB before you attempt to call distanceTo()

mbaird