@@ -15,20 +15,25 @@ import androidx.compose.ui.res.painterResource
1515import androidx.compose.ui.text.font.FontWeight
1616import androidx.compose.ui.unit.dp
1717import androidx.compose.ui.unit.sp
18+ // Add imports for geojson Point & BoundingBox
19+ import com.mapbox.geojson.Point
20+ import com.mapbox.geojson.BoundingBox
21+ import com.mapbox.maps.dsl.cameraOptions
1822import com.mapbox.maps.extension.compose.animation.viewport.MapViewportState
1923import com.mapbox.maps.plugin.animation.MapAnimationOptions
20- import com.mapbox.maps.dsl.cameraOptions
21- import com.mapbox.search.SearchSelectionCallback
2224import com.mapbox.search.ApiType
2325import com.mapbox.search.ResponseInfo
2426import com.mapbox.search.SearchEngine
2527import com.mapbox.search.SearchEngineSettings
2628import com.mapbox.search.SearchOptions
29+ import com.mapbox.search.SearchSuggestionsCallback
30+ import com.mapbox.search.SearchSelectionCallback
2731import com.mapbox.search.result.SearchResult
2832import com.mapbox.search.result.SearchSuggestion
2933import com.mapbox.search.result.SearchSuggestionType.Category
3034
3135
36+
3237@OptIn(ExperimentalMaterial3Api ::class )
3338@Composable
3439fun SearchScreen (
@@ -61,9 +66,11 @@ fun SearchScreen(
6166 searchEngine.search(
6267 newQuery,
6368 SearchOptions (
64- limit = 10
69+ // Coorindates to Toronto's Distillery District
70+ proximity = Point .fromLngLat(- 79.35954 , 43.65050 ),
71+ limit = 10 ,
6572 ),
66- callback = object : com.mapbox.search. SearchSuggestionsCallback {
73+ callback = object : SearchSuggestionsCallback {
6774 override fun onSuggestions (
6875 list : List <SearchSuggestion >,
6976 responseInfo : ResponseInfo
@@ -86,15 +93,15 @@ fun SearchScreen(
8693 modifier = Modifier
8794 .fillMaxWidth()
8895 .padding(8 .dp),
89- colors = TextFieldDefaults .outlinedTextFieldColors(
90- containerColor = Color .White , // White background
96+ colors = OutlinedTextFieldDefaults .colors(
97+ focusedContainerColor = Color .White , // White background
98+ unfocusedContainerColor = Color .White ,
9199 focusedBorderColor = Color .Gray , // Grey border when focused
92100 unfocusedBorderColor = Color .LightGray // Grey border when unfocused (lighter)
93101 ),
94102 shape = RoundedCornerShape (8 .dp)
95103 )
96104
97-
98105 Spacer (modifier = Modifier .height(16 .dp))
99106
100107 // Suggestions list anchored right below the TextField
@@ -105,7 +112,7 @@ fun SearchScreen(
105112 shape = RoundedCornerShape (8 .dp),
106113 modifier = Modifier
107114 .fillMaxWidth()
108- .padding(top= 8 .dp, start = 16 .dp, end = 16 .dp)
115+ .padding(top = 8 .dp)
109116 .heightIn(max = 500 .dp)
110117 ) {
111118 val scrollState = rememberScrollState()
@@ -114,17 +121,15 @@ fun SearchScreen(
114121 .padding(16 .dp)
115122 .verticalScroll(scrollState)
116123 ) {
124+
117125 // Filter out category suggestion types
118126 val filteredSuggestions = suggestions.filter { it.type !is Category }
119127
120128 filteredSuggestions.forEachIndexed { index, suggestion ->
121129
122130 val distanceKm = suggestion.distanceMeters?.div(1000.0 )
123131 val addressText = suggestion.fullAddress
124- ? : listOfNotNull(
125- suggestion.address?.region,
126- suggestion.address?.country
127- ).joinToString(" , " )
132+ ? : listOfNotNull(suggestion.address?.region, suggestion.address?.country).joinToString(" , " )
128133
129134 Row (
130135 modifier = Modifier
@@ -198,6 +203,7 @@ fun handleSuggestionSelection(
198203 // When user selects a suggestion:
199204 onSuggestionSelected(result)
200205 val coordinate = result.coordinate
206+
201207 val camera = cameraOptions {
202208 center(coordinate)
203209 zoom(14.0 )
@@ -208,6 +214,7 @@ fun handleSuggestionSelection(
208214 .build()
209215
210216 mapViewportState.flyTo(camera, animationOptions)
217+
211218 }
212219
213220 override fun onResults (
@@ -216,18 +223,6 @@ fun handleSuggestionSelection(
216223 responseInfo : ResponseInfo
217224 ) {
218225 // handle multiple results (category, brand, etc.)
219- results.forEachIndexed { index, result ->
220- Log .d(" Result[$index ]" , """
221- ID: ${result.id}
222- Name: ${result.name}
223- Description: ${result.descriptionText ? : " N/A" }
224- Place: ${result.address?.place ? : " N/A" }
225- Region: ${result.address?.region ? : " N/A" }
226- Country: ${result.address?.country ? : " N/A" }
227-
228- -----
229- """ .trimIndent())
230- }
231226 }
232227
233228
0 commit comments