Nominatim

This commit is contained in:
Dimitris
2026-03-30 10:00:16 +02:00
parent 9def7a5c64
commit 60b842d883
2 changed files with 3 additions and 43 deletions
@@ -28,9 +28,7 @@ abstract class NavigationRepository {
abstract fun getTraffic(context: Context, location: Location, carOrientation: Float): String abstract fun getTraffic(context: Context, location: Location, carOrientation: Float): String
fun getRouteDistance( fun getRouteDistance(
currentLocation: Location, currentLocation: Location,
location: Location, location: Location
carOrientation: Float,
context: Context
): Double { ): Double {
if (currentLocation.latitude == 0.0) if (currentLocation.latitude == 0.0)
return 0.0 return 0.0
@@ -77,7 +75,7 @@ abstract class NavigationRepository {
"Accept", "Accept",
"application/json" "application/json"
) // The format of response we want to get from the server ) // The format of response we want to get from the server
httpURLConnection.setRequestProperty("User-Agent", "email=nominatim@kouros-online.de"); httpURLConnection.setRequestProperty("User-Agent", "email=nominatim@kouros-online.de")
httpURLConnection.requestMethod = "GET" httpURLConnection.requestMethod = "GET"
val responseCode = httpURLConnection.responseCode val responseCode = httpURLConnection.responseCode
if (responseCode == HttpURLConnection.HTTP_OK) { if (responseCode == HttpURLConnection.HTTP_OK) {
@@ -5,8 +5,6 @@ import android.content.Context
import android.location.Location import android.location.Location
import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.toMutableStateList import androidx.compose.runtime.toMutableStateList
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
@@ -103,32 +101,6 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
} }
/**
* Loads the most recent place from Preferences and calculates its distance.
* Posts the result to recentPlace LiveData if distance > 1km.
*/
fun loadRecentPlace(location: Location, carOrientation: Float, context: Context) {
viewModelScope.launch(Dispatchers.IO) {
try {
val settingsRepository = getSettingsRepository(context)
val recentPlaces = settingsRepository.recentPlacesFlow.first()
val gson = GsonBuilder().serializeNulls().create()
val places = gson.fromJson(recentPlaces, Places::class.java)
for (place in places.places.sortedBy { it.lastDate }) {
val plLocation = location(place.longitude, place.latitude)
val distance = plLocation.distanceTo(location)
place.distance = distance
if (place.distance > 200F) {
recentPlace.postValue(place)
return@launch
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
/** /**
* Loads all recent places from Preferences and calculates distances. * Loads all recent places from Preferences and calculates distances.
* Posts the sorted list to places LiveData. * Posts the sorted list to places LiveData.
@@ -151,9 +123,7 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
val distance = val distance =
repository.getRouteDistance( repository.getRouteDistance(
location, location,
plLocation, plLocation
carOrientation,
context
) )
place.distance = distance.toFloat() place.distance = distance.toFloat()
place.id = id place.id = id
@@ -494,14 +464,6 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
deletePlace(context, place) deletePlace(context, place)
} }
/**
* Deletes a place from recent destinations in Preferences.
*/
fun deleteRecent(context: Context, place: Place) {
place.category = Constants.RECENT
deletePlace(context, place)
}
/** /**
* Deletes a place from Preferences matching name and category. * Deletes a place from Preferences matching name and category.
*/ */