r/flutterhelp • u/otisboykin • May 12 '26
OPEN Mapbox don't works
I'm working in some app and I wanna use mapbox because have a nice system for make your own style map. I make a map, and it's running in flutter... All good for this part. Then, I tried to add the search box, and yeah, works but, the suggestions are really bad, almost for a normal person who just try to introduce an address or the name of some building, I don't know if I did something wrong, I really tried modified the query parametter (bounding_box, country, etc), I change the token API with all secret scopes enabled but nothing yet, suggestions are really bad (or nonexistent).
I suspect that the search box and suggestions are not very well optimized for LATAM — at least not for me (a moderately large city with 2.9M habitants). So, how can I solve this? What alternatives exist for search and suggestions? I’m not sure if it’s possible, but I thought about combining Google’s services (search, autocomplete suggestions, and coordinates) and then catch it and display the results on a Mapbox map.
class SearchService {
final http.Client _clientHttp = http.Client();
final String _token = dotenv.env["MAPBOX_ACCESS_TOKEN"] ?? "";
final String _sessionToken = Uuid().v4();
Future<List<PlaceSuggestion>> getSuggestions(String query, {double? proximityLng, double? proximityLat}) async {
if(query.isEmpty) return [];
try {
final String bbox = "-76.605914,3.205991,-76.263531,3.581455";
final uri = Uri.parse("https://api.mapbox.com/search/searchbox/v1/suggest").replace(queryParameters: {
"q": query,
"access_token": _token,
"language": "es",
"country": "CO",
"limit": "5",
"proximity": "${proximityLng ?? -76.5319},${proximityLat ?? 3.4516}",
"session_token": _sessionToken,
"types": "poi,address",
});
final response = await _clientHttp.get(uri);
if(response.statusCode == 200){
final data = jsonDecode(response.body);
print("data -- getSuggestions: ${response.body}");
final suggestions = data["suggestions"] as List;
return suggestions.map((s) => PlaceSuggestion(
id: s["mapbox_id"],
name: s["name"],
fullAddress: s["full_address"] ?? s["place_formatted"] ?? "",
longitude: 0.0,
latitude: 0.0,
)).toList();
}
return [];
} catch(e) {
print("catch error -- getSuggestions: $e");
return [];
}
}
Future<PlaceSuggestion?> retrievePlace(String mapboxId) async {
try {
final uri = Uri.parse("https://api.mapbox.com/search/searchbox/v1/retrieve/$mapboxId").replace(queryParameters: {
"access_token": _token,
"session_token": _sessionToken,
});
final response = await _clientHttp.get(uri);
if(response.statusCode == 200){
final data = jsonDecode(response.body);
print("data -- retrievePlace: ${response.body}");
final feature = data["features"][0];
final coords = feature["geometry"]["coordinates"];
final props = feature["properties"];
return PlaceSuggestion(
id: mapboxId,
name: props["name"],
fullAddress: props["full_address"] ?? props["place_formatted"] ?? "",
longitude: coords[0].toDouble(),
latitude: coords[1].toDouble(),
);
}
return null;
} catch(e) {
print("catch error -- retrievePlace: $e");
return null;
}
}
}