ref: e4d7079147c16b0d67cd39e35f5d943644d24c68
app/src/main/java/xyz/apiote/bimba/czwek/search/geocoder.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
package xyz.apiote.bimba.czwek.search import android.content.Context import android.database.sqlite.SQLiteDatabase import android.location.Location fun findPlace(context: Context, name: String): Location? { val db = SQLiteDatabase.openOrCreateDatabase(context.getDatabasePath("geocoding").path, null) val cursor = db.rawQuery( "select lat, lon from place_names join places using(id) where name = ?", arrayOf(name) ) if (!cursor.moveToNext()) { cursor.close() db.close() return null } val location = Location(null).apply { latitude = cursor.getDouble(0) longitude = cursor.getDouble(1) } cursor.close() db.close() return location } |