[GIS] Centering MapBox map on location via JavaScript (not using ‘flyTo’)

mapbox

I'm trying to find a way to immediately centre a MapBox map on a given location using JavaScript and the closest example I've found so far is to use the 'flyTo' function:

map.flyTo({center: [device.lon, device.lat]});

I'm probably missing something obvious, but how do I just tell the map to immediately jump to that location?

Best Answer

I solved it with the following line:

map.setCenter([device.lon, device.lat]);
Related Question