-1

All the examples I've seen for adding a marker to the map show the marker being added in the "onMapReady" callback or the "onMapClick" callback. I have an app that periodically finds the user's latitude and longitude and I want to add a marker to the map when the lat and lng updates. This happens outside of the previously mentioned callbacks. How would I do that? I need access to the Style object of the map but it's only accesible inside the callbacks.

riastrad
  • 1,624
  • 10
  • 22

1 Answers1

1

The reason these callbacks (in particular onMapReady) are used in all the examples is to ensure that the mapboxMap objects's style has been loaded by the time you attempt to modify it - if it isn't there is the potential for some asynchronous weirdness as the map renders.

I would recommend you still include the logic for adding the periodic lat/lon coordinates as markers within the onMapReady callback.


⚠️ Disclaimer: I currently work for Mapbox ⚠️

riastrad
  • 1,624
  • 10
  • 22
  • thanks @riastrad. if onMapReady get's called only once when the map is loaded, how would you recommend I make periodic updates to the map?Maybe set up a listener of some sort? – Adam Marciniak Mar 20 '19 at 16:50