From 2231b4b79408b3c7b09c73a179b0d15685b8a169 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Mon, 21 Mar 2011 19:10:44 +0100 Subject: [PATCH] storage: support fetching neighbors sorted by distance --- src/StorageDatabase.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/StorageDatabase.scala b/src/StorageDatabase.scala index 32d8a8a..ca807c6 100644 --- a/src/StorageDatabase.scala +++ b/src/StorageDatabase.scala @@ -59,6 +59,9 @@ object StorageDatabase { SYMBOL, COMMENT, ORIGIN, QRG) lazy val TABLE_DROP = "DROP TABLE %s".format(TABLE) lazy val COLUMNS = Array(_ID, TS, CALL, LAT, LON, SYMBOL, COMMENT, SPEED, COURSE, ALT, ORIGIN, QRG) + lazy val COL_DIST = "((lat - %d)*(lat - %d) + (lon - %d)*(lon - %d)) as dist" + + val COLUMN_TS = 1 val COLUMN_CALL = 2 val COLUMN_LAT = 3 val COLUMN_LON = 4 @@ -192,6 +195,13 @@ class StorageDatabase(context : Context) extends "call LIKE ?", Array(querycall), "call", null, null, null) } + def getNeighbors(lat : Int, lon : Int, limit : String) : Cursor = { + // add a distance column to the query + val newcols = Position.COLUMNS :+ Position.COL_DIST.format(lat, lat, lon, lon) + getReadableDatabase().query(Position.TABLE, newcols, + null, null, + "call", null, "dist", limit) + } def addPost(ts : Long, posttype : Int, status : String, message : String) { val cv = new ContentValues()