I am able to show map with custom lat and long but i want to dynamically show marker of shop in google map,but i am kind of stuck at what to next,i tried some example but it i can't figure it out how to do this,can any one help me on this,i have no problem getting the lat and long from api but i am not sure how to set up marker in google map.
Variable initialized
GoogleMapController mapController;
final LatLng _center = const LatLng(45.521563, -122.677433);
Set<Marker> markers = Set();
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
Map Widget
Widget MapViewData() {
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
),
);
}
Api functions returs lat and long along with details
Future<void> Mapdata() async {
var response = await http.get(
"${Urls.baseUrl}${Urls.GetMapData}?radius=100&locale=en",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer ${userToken}",
"Accept": "application/json"
});
Map<String, dynamic> value = json.decode(response.body);
if (response.statusCode == 200) {
try {
var data = value['data'];
var array = data['shops'];
for (int i = 0; i < array.length; i++) {
var obj = array[i];
mapLists.add(NearByMapModel(
obj['id'],
obj['name'],
obj['address'],
obj['latitude'],
obj['longitude'],
));
}
} catch (e) {
e.toString();
}
}
}