开发者

Finding the distance between 2 points in Android using Cursor and the distanceTo() method

开发者 https://www.devze.com 2022-12-25 04:34 出处:网络
I am trying to calculate the distance between the first GPS point stored in a SQLite database and the last GPs point stored.

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.getWritableDatab开发者_StackOverflow社区ase();
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


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

The method distanceTo(Location) is available on the Location class:
https://developer.android.com/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().

0

精彩评论

暂无评论...
验证码 换一张
取 消