ref: 7b6047ea6c99eac164e6e40cf9837f49daa1d060
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 28 29 30 31 |
// SPDX-FileCopyrightText: Adam Evyčędo // // SPDX-License-Identifier: AGPL-3.0-or-later 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 } |