@Override public void run() { Log.v(Program.LOG, "DatabaseSearcher.run()"); double radius = PreferenceManager.getDefaultSharedPreferences(context) .getInt(context.getResources().getString(R.string.radius), 20); Location l = StoreFinderApplication.getLastKnownLocation(); double lat = l.getLatitude(); double lon = l.getLongitude(); database = database.open(); db = database.getDatabase(); Cursor c = db.query( "store", new String[] { "_id", "name", "address", "city", "state", "zip", "phone", "latitude", "longitude" }, "latitude > " + (lat - radius / MILES_PER_LATLONG) + " AND latitude < " + (lat + radius / MILES_PER_LATLONG) + " AND longitude > " + (lon - radius / MILES_PER_LATLONG) + " AND longitude < " + (lon + radius / MILES_PER_LATLONG), null, null, null, null); double latitude, longitude; c.moveToFirst(); if (c.getCount() > 0) { do { latitude = c.getDouble(7); longitude = c.getDouble(8); float[] results = new float[3]; Location.distanceBetween(lat, lon, latitude, longitude, results); double distance = results[0] * Program.MILES_PER_METER; if (distance > radius) // Make user customizable search distance continue; Store store = new Store(); store.setId(c.getInt(0)); store.setName(c.getString(1)); store.setAddress(c.getString(2)); store.setCitystate(c.getString(3) + ", " + c.getString(4) + " " + c.getString(5)); store.setPhone(c.getString(6)); store.setDistance(distance); Location loc = new Location(""); loc.setLatitude(latitude); loc.setLongitude(longitude); store.setLocation(loc); Message msg = new Message(); Bundle b = new Bundle(); b.putSerializable("store", store); msg.setData(b); msg.what = WHAT_SEARCHDB; handler.sendMessage(msg); } while (c.moveToNext()); } c.close(); database.close(); Message finish = new Message(); finish.what = WHAT_FINISHEDSEARCH; handler.sendMessage(finish); }