markers flutter_map code example

Example: flutter_map marker

class _MapDataState extends State<MapData> {
      List<SitesList> sl = [];
      List<SnoTelSite> sts = [];
      var marker = <Marker>[];

      _MapDataState(){
        print("map data state");
        loadSites().then((sitesdata) {
          print('Loaded Sites Asset JSON');
          //clone sitesdata into sts array
          sts..addAll(sitesdata);
          sts.forEach((s) {
            marker.add(
              Marker(
                point: new LatLng(double.parse(s.lat),double.parse(s.lng)),
                builder: (ctx) => _MarkerPopUp(sitename: s.name, siteelevation: s.elevation, siteid: s.siteID,),
              ),
            );
          });
        });
      }

      // @override
      // initState() {
      //   print("INIT STATE");
      //   super.initState();
      // }

      //local load assets ... constants hold path snotelsitesjson
      Future<String> _loadSiteAssets() async {
        return await rootBundle.loadString(snotelsitesjson);
      }

      Future loadSites() async {
        String jsonString = await _loadSiteAssets();
        final jsonResponse = json.decode(jsonString);
        SitesList sitesList = new SitesList.fromJson(jsonResponse);
        return sitesList.sites;
      }

    //main build and screen layout
      @override
      Widget build(BuildContext context) {
        print("BUILD LAYOUT");
        return MaterialApp(
          theme: ThemeData(
            primarySwatch: Colors.cyan,
          ),
          home: Scaffold(
              appBar: AppBar(
                backgroundColor: Colors.white,
                leading: Icon(Icons.ac_unit),
                title: Text("SnoTel Map"),
                actions: <Widget>[
                  IconButton(
                    icon: Icon(Icons.favorite),
                    onPressed: () {
                      debugPrint("Favorites");
                    },
                  ),
                  IconButton(
                    icon: Icon(Icons.feedback),
                    onPressed: () {
                      debugPrint("Message sent");
                    },
                  ),
                ],
              ),
              body: _MapWidget()),
        );
      }
    }

Tags:

Misc Example