flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.03k stars 498 forks source link

mapbox for flutter: TypeError: Cannot set properties of undefined (setting 'accessToken') #1374

Closed MauroGentile closed 5 months ago

MauroGentile commented 10 months ago

Thiis probably due to me not setting up correctly mapbox for flutter.

1) I created an access token with donwloads:read permission AT is something like sk.XXXXX 2) In web/imdex.html I have added the following 2 lines

3) I have a widget like:

child: MapboxMap( accessToken: <accesstoken>, styleString: 'mapbox://styles/mapbox/streets-v11', // You can change the map style here onMapCreated: (controller) { setState(() { _controller = controller; }); },

When I run this widget i get TypeError: Cannot set properties of undefined (setting 'accessToken')

aardrop commented 9 months ago

@MauroGentile did you find a solution to this? I am facing the same issue. I have the example running fine but can't get it to run in my project.

aardrop commented 9 months ago

I tried updating the mapbox js version and stopped getting this error:

<!-- Mapbox -->
  <script src='https://api.mapbox.com/mapbox-gl-js/v2.8.2/mapbox-gl.js'></script>
MauroGentile commented 8 months ago

Your string in the HTM is correct. I have the following.


  <script src='https://api.mapbox.com/mapbox-gl-js/v2.7.0/mapbox-gl.js'></script>
  <link href='https://api.mapbox.com/mapbox-gl-js/v2.7.0/mapbox-gl.css' rel='stylesheet' />
</body>

The error in my case is that I was using the wrong StyleID.

Use this: TileLayer(urlTemplate: StyleId), where StyleId has a format like: 'https://api.mapbox.com/styles/v1/userName/yyyyyy?access_token=pk.xxxxx' Let me know if this solves

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

aardrop commented 5 months ago

I had that as well in a couple of instances and was able to debug it in the web inspect console or the Xcode runtime for anyone else coming across this.