Cloud Stack Ninja

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}?latitude=${Constants.latitude}&longitude=${Constants.longitude}&radius=100&locale=en&page=1",
        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];
          print("Image link " + obj['name']);
          mapLists.add(NearByMapModel(
            obj['id'],
            obj['owner_id'],
            obj['brand_id'],
            obj['region_id'],
            obj['country_id'],
            obj['name'],
            Urls.baseImageUrl + obj['logo'],
            Urls.baseImageUrl + obj['original_logo'],
            obj['address'],
            obj['latitude'],
            obj['longitude'],
          ));
       
        }
      } catch (e) {
        e.toString();
      }
    }
  }


Read more here: https://stackoverflow.com/questions/64401482/setup-marker-in-google-map-flutter

Content Attribution

This content was originally published by Assassin at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: