So i am using the googlemaps package and when a user zooms in/out i need to show/hide various markers based on distance. the markers data comes from a json future. I can see it zoom in/out, but i cannot get it to loop through my amenities future. i know i am probably using the wrong thing(FutureBuilder) what should i be using instead? thanks
class _AlreadyHereState extends State<AlreadyHere>
with SingleTickerProviderStateMixin {
late Future<Amenities> amenities;
@override
void initState() {
super.initState();
amenities = AmenitiesData.getAmenities();
}
onCameraMove(CameraPosition position) {
double distance;
if (position.zoom >= 10.1) {
// Create Markers From Amenities
print("Add Marker - $position");
FutureBuilder(
future: amenities,
builder: (BuildContext context, snapshot) {
if (snapshot.hasData) {
snapshot.data!.amenities.forEach((el) {
distance = calculateDistance(position.target.latitude,
position.target.latitude, el.latitude, el.longitude);
if (distance <= 5) {
//Create Marker
} else {
// if marker exists remove marker
}
});
}
throw ('error');
});
} else if (position.zoom <= 10.0) {
print("Remove Marker - $position");
//Remove Markers
}
}