I am working with the MapBox API and I want to sort all the stores on pressing the getCurrentPosition() button. I can do this when I search a location in the searchBox provided, because I change the location of the event object to the location of the user and sort all stores from that object.
Get current long, lat and store in user_long and user_lat
navigator.geolocation.getCurrentPosition(position => {
user_lat = position.coords.latitude;
user_long = position.coords.longitude;
});
Assign that long and lat to an event object
geocoder.on('result', (event) => {
/* Get the coordinate of the search result */
const searchResult = event.result.geometry;
userLoc = searchResult;
// Make an object like event and assign that object the users location
userLoc["coordinates"][0] = user_long;
userLoc["coordinates"][1] = user_lat;
From here on its the same as the documentation.
How do I do this in the getCurrentPosition() button when I dont have 'event'?