I have a list of type Map<String, dynamic>
named positionMarkers
which holds latitudes and longitudes along with their ID’s that I would like to map accordingly into a list of type Marker i.e List<Marker>
. I need the id in positionMarkers
and the lat and lng to go into MarkerId()
and LatLng()
respectively. I’m pretty sure that this can be achieved by using loops but cannot seem to figure how. Any help would be appreciated:
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class MapMarkers with ChangeNotifier {
List<Map<String, dynamic>> positionMarkers = [
{
'id': 1,
'lat': 22.6434340,
'lng': 88.446740,
},
{
'id': 2,
'lat': 22.6435442,
'lng': 88.456742,
},
{
'id': 3,
'lat': 22.6436544,
'lng': 88.466744,
},
{
'id': 4,
'lat': 22.6437646,
'lng': 88.476746,
},
{'id': 5, 'lat': 22.6438748, 'lng': 88.486748}
];
final List<Marker> markers = [
Marker(
markerId: MarkerId(),
position: LatLng(),
infoWindow: InfoWindow(),
)
];
}
2
Answers
Is this what you want?
Try this,