Skip to content

Commit

Permalink
Show user location marker
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Jan 22, 2025
1 parent fddc866 commit 3ae7907
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/src/main/kotlin/location/UserLocationRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class UserLocationRepository(
}

private fun onNewLocation(location: Location) {
Log.d(TAG, "Got new location: ${location.latitude},${location.longitude}")
_location.update { LatLng(location.latitude, location.longitude) }
}

Expand Down
39 changes: 39 additions & 0 deletions app/src/main/kotlin/map/MapFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package map

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
Expand Down Expand Up @@ -62,8 +63,12 @@ import org.maplibre.android.annotations.Marker
import org.maplibre.android.annotations.MarkerOptions
import org.maplibre.android.camera.CameraUpdateFactory
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.location.LocationComponentActivationOptions
import org.maplibre.android.location.LocationComponentOptions
import org.maplibre.android.location.engine.LocationEngineRequest
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.MapLibreMap.OnCameraIdleListener
import org.maplibre.android.maps.Style
import reports.ReportsFragment
import search.SearchAdapter
import search.SearchModel
Expand Down Expand Up @@ -101,9 +106,43 @@ class MapFragment : Fragment() {
) {
if (it.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false)) {
model.onLocationPermissionGranted()
onLocationPermissionsGranted()
}
}

@SuppressLint("MissingPermission")
private fun onLocationPermissionsGranted() {
binding.map.getMapAsync { map ->
map.getStyle { style ->
val locationComponentOptions =
LocationComponentOptions.builder(requireContext())
.pulseEnabled(true)
.build()
val locationComponentActivationOptions =
buildLocationComponentActivationOptions(style, locationComponentOptions)
map.locationComponent.activateLocationComponent(locationComponentActivationOptions)
map.locationComponent.isLocationComponentEnabled = true
}
}
}

private fun buildLocationComponentActivationOptions(
style: Style,
locationComponentOptions: LocationComponentOptions
): LocationComponentActivationOptions {
return LocationComponentActivationOptions
.builder(requireContext(), style)
.locationComponentOptions(locationComponentOptions)
.useDefaultLocationEngine(true)
.locationEngineRequest(
LocationEngineRequest.Builder(750)
.setFastestInterval(750)
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
.build()
)
.build()
}

private var emptyClusterBitmap: Bitmap? = null

override fun onCreateView(
Expand Down

0 comments on commit 3ae7907

Please sign in to comment.