Go to place in mapbox by url

I am using Mapbox (Mapbox GL-JS) and I would like to let site users go to a url that positions the map based on the coordinates. I was thinking something like this: How to read GET data from a URL using JavaScript?. Any Ideas how to start?

1 answer

  • answered 2021-02-23 10:26 Steve Bennett

    If all you want is for the map to initialise at a location depending on the URL, you can achieve this by initialising the map with:

    const map = new mapboxgl.Map({
       // ...
       // hash: true

    When you move the map around, the URL will update, something like localhost:8000/#15/-144.9,-37.8.

    If this wasn't what you were asking, I suggest putting more details in your question.