Skip to content

Commit

Permalink
Merge pull request #123 from makeen-project/ALS-1969
Browse files Browse the repository at this point in the history
ALS-1969 Location is disabled then the search should consider the centre of the map
  • Loading branch information
olegfilimonov authored Jan 28, 2025
2 parents 0f1ba9e + d1fd380 commit 3c5bdd5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5759,7 +5759,7 @@ class ExploreFragment :
mapLibreMap.cameraPosition.target?.let {
LatLng(
it.latitude,
mapLibreMap.cameraPosition.target!!.longitude,
it.longitude,
)
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/aws/amazonlocation/utils/MapHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ class MapHelper(
}
}

fun getLiveLocation(): LatLng? {
fun getLiveLocation(isDefaultLocationNeeded: Boolean = true): LatLng? {
var mLatLng: LatLng? = null
if (mMapLibreMap?.locationComponent?.isLocationComponentActivated == true) {
mMapLibreMap?.locationComponent?.lastKnownLocation?.apply {
Expand All @@ -1075,6 +1075,8 @@ class MapHelper(
)
}
}
if (!isDefaultLocationNeeded) return mLatLng

return if (mLatLng == null) {
mDefaultLatLng
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PlacesProvider(
getPlaceClient: GeoPlacesClient?,
): SearchSuggestionResponse {
try {
val liveLocation = mMapHelper.getLiveLocation()
val liveLocation = mMapHelper.getLiveLocation(isDefaultLocationNeeded = false)
var isLatLng = false
var suggestResponse: SuggestResponse? = null
var reverseGeocodeResponse: ReverseGeocodeResponse? = null
Expand Down Expand Up @@ -111,67 +111,67 @@ class PlacesProvider(
}

reverseGeocodeResponse?.resultItems?.forEach {
liveLocation?.let { liveLocation ->
it.position?.let { position ->
val distance = TurfMeasurement.distance(
it.position?.let { position ->
val distance = if (liveLocation != null) {
TurfMeasurement.distance(
Point.fromLngLat(liveLocation.longitude, liveLocation.latitude),
Point.fromLngLat(position[0], position[1]),
TurfConstants.UNIT_METRES
)
val mSearchSuggestionData: SearchSuggestionData =
if (it.placeId.isNotEmpty()) {
SearchSuggestionData(
placeId = it.placeId,
text = it.address?.label,
amazonLocationAddress = it.address,
distance = distance,
position = listOf(position[0], position[1]),
)
} else {
SearchSuggestionData(text = it.address?.label)
}
mList.add(mSearchSuggestionData)
}
} else it.distance.toDouble()

val mSearchSuggestionData: SearchSuggestionData =
if (it.placeId.isNotEmpty()) {
SearchSuggestionData(
placeId = it.placeId,
text = it.address?.label,
amazonLocationAddress = it.address,
distance = distance,
position = listOf(position[0], position[1]),
)
} else {
SearchSuggestionData(text = it.address?.label)
}
mList.add(mSearchSuggestionData)
}
}
suggestResponse?.resultItems?.forEach {
liveLocation?.let { liveLocation ->
if (!it.place?.position.isNullOrEmpty()) {
it.place?.position?.let { position ->
val distance = TurfMeasurement.distance(
if (!it.place?.position.isNullOrEmpty()) {
it.place?.position?.let { position ->
val distance = if (liveLocation != null) {
TurfMeasurement.distance(
Point.fromLngLat(liveLocation.longitude, liveLocation.latitude),
Point.fromLngLat(position[0], position[1]),
TurfConstants.UNIT_METRES
)
} else it.place!!.distance.toDouble()

if (!it.place?.placeId.isNullOrEmpty()) {
if (!it.place?.placeId.isNullOrEmpty()) {
mList.add(
SearchSuggestionData(
placeId = it.place!!.placeId,
searchText = searchText,
text = it.place?.address?.label,
amazonLocationAddress = it.place?.address,
distance = distance,
position = listOf(position[0], position[1]),
),
)
} else {
it.query?.let { query ->
mList.add(
SearchSuggestionData(
placeId = it.place!!.placeId,
searchText = searchText,
text = it.place?.address?.label,
amazonLocationAddress = it.place?.address,
distance = distance,
position = listOf(position[0], position[1]),
),
SearchSuggestionData(text = it.title, queryId = query.queryId),
)
} else {
it.query?.let { query ->
mList.add(
SearchSuggestionData(text = it.title, queryId = query.queryId),
)
}
}
}
} else {
it.query?.let { query ->
mList.add(
SearchSuggestionData(text = it.title, queryId = query.queryId),
)
}
}
} else {
it.query?.let { query ->
mList.add(
SearchSuggestionData(text = it.title, queryId = query.queryId),
)
}
}

}
response.data = mList
return response
Expand Down Expand Up @@ -216,7 +216,7 @@ class PlacesProvider(
getPlaceClient: GeoPlacesClient?,
): SearchSuggestionResponse? =
try {
val liveLocation = mMapHelper.getLiveLocation()
val liveLocation = mMapHelper.getLiveLocation(isDefaultLocationNeeded = false)
val request =
SearchTextRequest {
if (mText != null) this.queryText = mText
Expand Down Expand Up @@ -249,28 +249,28 @@ class PlacesProvider(
addMarkerBasedOnLatLng(searchSuggestionResponse, text, mList)
} else {
response?.resultItems?.forEach { result ->
liveLocation?.let {
result.position?.let {
val distance = TurfMeasurement.distance(
result.position?.let {
val distance = if (liveLocation != null) {
TurfMeasurement.distance(
Point.fromLngLat(liveLocation.longitude, liveLocation.latitude),
Point.fromLngLat(it[0], it[1]),
TurfConstants.UNIT_METRES
)
val placeData =
SearchSuggestionData(
placeId = result.placeId,
searchText = text,
amazonLocationAddress = result.address,
text = result.title,
position =
} else result.distance.toDouble()
val placeData =
SearchSuggestionData(
placeId = result.placeId,
searchText = text,
amazonLocationAddress = result.address,
text = result.title,
position =
listOf(
it[0], it[1]
),
distance =
distance,
)
mList.add(placeData)
}
)
mList.add(placeData)
}
}
}
Expand Down

0 comments on commit 3c5bdd5

Please sign in to comment.