Amenities

This commit is contained in:
Dimitris
2025-12-17 09:31:12 +01:00
parent d546ede0e5
commit ed24e71473
21 changed files with 284 additions and 246 deletions

View File

@@ -58,7 +58,6 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.maplibre.compose)
implementation("hu.supercluster:overpasser:0.2.2")
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)

View File

@@ -68,8 +68,9 @@ data class StepData (
// GeoJSON data classes
@Serializable
data class GeoJsonLineString(
data class GeoJsonType(
val type: String,
val coordinates: List<List<Double>>
)
@@ -77,7 +78,7 @@ data class GeoJsonLineString(
@Serializable
data class GeoJsonFeature(
val type: String,
val geometry: GeoJsonLineString
val geometry: GeoJsonType,
)
@Serializable
@@ -156,7 +157,7 @@ object Constants {
const val FAVORITES: String = "Favorites"
const val GAS_STATION: String ="GasStation"
const val FUEL_STATION: String ="fuel"
const val PHARMACY: String ="pharmacy"

View File

@@ -95,7 +95,7 @@ data class Route(
points.add(point)
}
pointLocations = points
routeGeoJson = createGeoJson(waypoints)
routeGeoJson = createGeoJson("LineString", waypoints)
centerLocation = createCenterLocation(routeGeoJson)
return Route(
maneuvers,

View File

@@ -9,6 +9,6 @@ data class Elements (
@SerializedName("id" ) var id : Long? = null,
@SerializedName("lat" ) var lat : Double? = null,
@SerializedName("lon" ) var lon : Double? = null,
@SerializedName("tags" ) var tags : Tags? = Tags()
@SerializedName("tags" ) var tags : Tags = Tags()
)

View File

@@ -1,45 +1,25 @@
package com.kouros.navigation.data
package com.kouros.navigation.data.overpass
import android.location.Location
import com.google.gson.GsonBuilder
import com.kouros.navigation.data.overpass.Amenity
import com.kouros.navigation.data.overpass.Elements
import com.kouros.navigation.utils.NavigationUtils.getBoundingBox2
import com.kouros.navigation.utils.NavigationUtils.getOverpassBbox
import hu.supercluster.overpasser.library.output.OutputFormat
import hu.supercluster.overpasser.library.output.OutputModificator
import hu.supercluster.overpasser.library.output.OutputOrder
import hu.supercluster.overpasser.library.output.OutputVerbosity
import hu.supercluster.overpasser.library.query.OverpassQuery
import com.kouros.navigation.utils.NavigationUtils
import java.io.OutputStreamWriter
import java.net.HttpURLConnection
import java.net.URL
class Overpass {
val overpassUrl = "https://overpass.kumi.systems/api/interpreter"
fun getAmenities(category: String, location: Location) : List<Elements> {
val boundingBox = getOverpassBbox(location, 2.0)
val bb = getBoundingBox2(location, 2.0)
val url = "https://overpass.kumi.systems/api/interpreter"
val httpURLConnection = URL(url).openConnection() as HttpURLConnection
val boundingBox = NavigationUtils.getOverpassBbox(location, 2.0)
val bb = NavigationUtils.getBoundingBox2(location, 2.0)
val httpURLConnection = URL(overpassUrl).openConnection() as HttpURLConnection
httpURLConnection.requestMethod = "POST"
httpURLConnection.setRequestProperty(
"Accept",
"application/json"
)
httpURLConnection.setDoOutput(true);
val query = OverpassQuery()
.format(OutputFormat.JSON)
.timeout(30)
.filterQuery()
.node()
.amenity("charging_station")
.tagNot("access", "private")
.boundingBox(bb.southernLat, bb.westernLon, bb.northerLat, bb.easternLon)
.end()
.output(OutputVerbosity.BODY, OutputModificator.CENTER, OutputOrder.QT, 100)
.build()
// define a query
val test = """
|[out:json];
@@ -56,12 +36,9 @@ class Overpass {
outputStreamWriter.flush()
// Check if the connection is successful
val responseCode = httpURLConnection.responseCode
println("Overpass: $responseCode")
if (responseCode == HttpURLConnection.HTTP_OK) {
val response = httpURLConnection.inputStream.bufferedReader()
.use { it.readText() } // defaults to UTF-8
val gson = GsonBuilder().serializeNulls().create()
val overpass = gson.fromJson(response, Amenity::class.java)
println("Overpass: $response")

View File

@@ -17,6 +17,6 @@ data class Tags (
@SerializedName("operator:wikipedia" ) var operatorWikipedia : String? = null,
@SerializedName("ref" ) var ref : String? = null,
@SerializedName("socket:type2" ) var socketType2 : String? = null,
@SerializedName("socket:type2:output" ) var socketType2Ooutput : String? = null
@SerializedName("socket:type2:output" ) var socketType2Output : String? = null
)

View File

@@ -52,7 +52,6 @@ open class RouteModel() {
this.routeState = routeState.copy(
route = null,
isNavigating = false,
// destination = Place(),
arrived = false,
maneuverType = 0,
currentShapeIndex = 0,

View File

@@ -13,7 +13,7 @@ import com.kouros.navigation.data.Constants
import com.kouros.navigation.data.Locations
import com.kouros.navigation.data.NavigationRepository
import com.kouros.navigation.data.ObjectBox.boxStore
import com.kouros.navigation.data.Overpass
import com.kouros.navigation.data.overpass.Overpass
import com.kouros.navigation.data.Place
import com.kouros.navigation.data.Place_
import com.kouros.navigation.data.SearchFilter
@@ -118,7 +118,6 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
.orderDesc(Place_.lastDate)
.build()
val results = query.find()
println("Favorites $results")
query.close()
for (place in results) {
val plLocation = location(place.longitude, place.latitude)
@@ -233,7 +232,6 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
val address = repository.reverseAddress(location)
val gson = GsonBuilder().serializeNulls().create()
val place = gson.fromJson(address, SearchResult::class.java)
println(place.address.road)
return place.address.road
}
@@ -271,7 +269,6 @@ class ViewModel(private val repository: NavigationRepository) : ViewModel() {
val current = LocalDateTime.now(ZoneOffset.UTC)
place.lastDate = current.atZone(ZoneOffset.UTC).toEpochSecond()
placeBox.put(place)
println("Save Place $place")
} catch (e: Exception) {
e.printStackTrace()
}

View File

@@ -8,7 +8,7 @@ import com.kouros.navigation.data.BoundingBox
import com.kouros.navigation.data.Constants.SHARED_PREF_KEY
import com.kouros.navigation.data.GeoJsonFeature
import com.kouros.navigation.data.GeoJsonFeatureCollection
import com.kouros.navigation.data.GeoJsonLineString
import com.kouros.navigation.data.GeoJsonType
import kotlinx.serialization.json.Json
import org.maplibre.geojson.FeatureCollection
import org.maplibre.geojson.Point
@@ -23,12 +23,9 @@ import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import kotlin.math.absoluteValue
import kotlin.math.asin
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.math.sin
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
@@ -149,9 +146,8 @@ object NavigationUtils {
// 4. Create and return the Location object.
return location(centerPoint.longitude(), centerPoint.latitude())
}
fun createGeoJson(lineCoordinates: List<List<Double>>): String {
val lineString = GeoJsonLineString(type = "LineString", coordinates = lineCoordinates)
fun createGeoJson(type : String, lineCoordinates: List<List<Double>>): String {
val lineString = GeoJsonType(type = type, coordinates = lineCoordinates)
val feature = GeoJsonFeature(type = "Feature", geometry = lineString)
val featureCollection =
GeoJsonFeatureCollection(type = "FeatureCollection", features = listOf(feature))
@@ -159,6 +155,8 @@ object NavigationUtils {
return jsonString
}
fun getOverpassBbox(location: Location, radius: Double): String {
val bbox = getBoundingBox(location.longitude, location.latitude, radius)
val neLon = bbox["ne"]?.get("lon")