iosflutterdartmapboxfluttermap

How to add map using package flutter_map?


I`m using package flutter_map to add map in my app (I do step by step in this video). My code like this:

FlutterMap(
  mapController: mapController,
  options: MapOptions(
    initialCenter: const LatLng(51.5, -0.09),
    initialZoom: 5,
  ),
  children: [
    TileLayer(
      tileProvider: AssetTileProvider(),
      urlTemplate:
          'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
    ),
  ],
),

But when i run, it show error in console:

Unable to load asset: "https://tile.openstreetmap.org/5/15/10.png"
Unable to load asset: "https://tile.openstreetmap.org/5/20/10.png"
...

And then i do step by step again in other video: https://youtu.be/hZwrcOTxDJI?si=2XiBv7_iKbZtFaDR It still show error: Unable to load asset: ...
I don't know why it's causing this issue even though I followed the instructions correctly. Can someone help me, please? Thank you so much.


Solution

  • You are using tileProvider as an AssetProvider.

    You should be using NetworkTileProvider.