Bimba.git

ref: 343255d5c2e7108dd510ca9e7707d2d3d67e0bc6

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
}