Repository navigation
[NMA-1079] (Explore-Dash) Sorting by distance - #823
Conversation
| eastLng == other.eastLng && | ||
| southLat == other.southLat && | ||
| westLng == other.westLng && | ||
| centerLat == other.centerLng && |
There was a problem hiding this comment.
Found a bug during unit testing
| val latitude: Double, | ||
| val longitude: Double, | ||
| val logoUrl: Bitmap | ||
| ) |
| private var markerManager: MarkerManager? = null | ||
| private var currentMapItems: List<SearchResult> = listOf() | ||
| private var markerCollection: MarkerManager.Collection? = null | ||
| private var circleManager: CircleManager? = null |
There was a problem hiding this comment.
Managers don't need to be stored
| center.latitude, center.longitude, | ||
| it.latitude ?: 0.0, it.longitude ?: 0.0 | ||
| ) | ||
| }.take(ExploreViewModel.MAX_MARKERS) |
There was a problem hiding this comment.
Only MAX_MARKERS closest to the center of the map are displayed
| } | ||
|
|
||
| private fun addCircleAroundCurrentPosition() { | ||
| currentLocationCircle = circleCollection?.addCircle(CircleOptions().apply { |
There was a problem hiding this comment.
No need to have a separate collection for a single circle.
| private fun addMarkerOnCurrentPosition() { | ||
| val bitmap = getBitmapFromDrawable(R.drawable.user_location_map_marker) | ||
| currentLocationMarker = markerCollection?.addMarker(MarkerOptions().apply { | ||
| currentLocationMarker = googleMap?.addMarker(MarkerOptions().apply { |
There was a problem hiding this comment.
There is no need to save the current location marker in the same collection as the merchant/atm markers. This simplifies managing other markers like handling clicks and calculating the difference to render.
|
|
||
| currentLocationMarker?.position = mCurrentUserLocation | ||
| currentLocationCircle?.center = mCurrentUserLocation | ||
| currentLocationCircle?.radius = currentAccuracy |
There was a problem hiding this comment.
Instead of re-creating the current location marker and circle, we can simply update their locations.
| pair.first.id, | ||
| it, it1, | ||
| try { | ||
| pair.second.get() |
There was a problem hiding this comment.
Calling .get() before rendering markers makes the map wait until all of the merchant/atm icons have been either resolved or failed to resolve. This can take several seconds with a slow connection. Better to add markers to the map incrementally as they are load or fail.
| withContext(Dispatchers.Main){ | ||
| exploreMarkers.forEach{ | ||
| it?.let { it1 -> addMarkerItemToMap(it1.latitude, it.longitude, it.logoUrl, it.id) } | ||
| private fun removeOldMarkers(newItems: List<SearchResult>) { |
There was a problem hiding this comment.
Instead of resetting the map on every collection change, we calculate the difference and only render new and remove old markers.
| return false | ||
| } | ||
|
|
||
| private fun handleClickOnMarkerItem(results: List<SearchResult>) { |
| CASE WHEN :sortByDistance = 1 THEN (latitude - :anchorLat)*(latitude - :anchorLat) + (longitude - :anchorLng)*(longitude - :anchorLng) END ASC, | ||
| CASE WHEN :sortByDistance = 0 THEN name END COLLATE NOCASE ASC |
There was a problem hiding this comment.
Very cool, here is the Pythagorean theorem.
HashEngineering
left a comment
There was a problem hiding this comment.
Very good. Tested.
ClaudeHangui
left a comment
There was a problem hiding this comment.
Nothing to add, looks awesome
If the user has location services enabled, physical results should be sorted by distance from the user location.
Issue being fixed or feature implemented
Related PR's and Dependencies
Screenshots / Videos
How Has This Been Tested?
Checklist: