From 3534190a42f7be2eaf2f10b9d140b0344aaea613 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Sun, 27 Mar 2011 00:51:20 +0100 Subject: [PATCH] fix distance overflow --- src/StorageDatabase.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/StorageDatabase.scala b/src/StorageDatabase.scala index 9397b9e..42a0ac3 100644 --- a/src/StorageDatabase.scala +++ b/src/StorageDatabase.scala @@ -61,7 +61,7 @@ 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)*%d/1000) as dist" + lazy val COL_DIST = "((lat - %d)*(lat - %d) + (lon - %d)*(lon - %d)*%d/100) as dist" val COLUMN_TS = 1 val COLUMN_CALL = 2 @@ -197,14 +197,14 @@ class StorageDatabase(context : Context) extends "call LIKE ?", Array(querycall), "call", null, null, null) } - def getNeighbors(lat : Int, lon : Int, ts : Long, limit : String) : Cursor = { + def getNeighbors(mycall : String, lat : Int, lon : Int, ts : Long, limit : String) : Cursor = { // calculate latitude correction - val corr = (cos(Pi*lat/180000000.)*cos(Pi*lat/180000000.)*1000).toInt + val corr = (cos(Pi*lat/180000000.)*cos(Pi*lat/180000000.)*100).toInt Log.d(TAG, "getNeighbors: correcting by %d".format(corr)) // add a distance column to the query val newcols = Position.COLUMNS :+ Position.COL_DIST.format(lat, lat, lon, lon, corr) getReadableDatabase().query(Position.TABLE, newcols, - "ts > ?", Array(ts.toString), + "ts > ? or call = ?", Array(ts.toString, mycall), "call", null, "dist", limit) }