I'm building an app and I need to know how to get what is the closest place based on my location. I have this code to get my location:
var userLatitude;
var userLongitude
navigator.geolocation.getCurrentPosition(function(position) {
userLatitude = position.coords.latitude;
userLongitude = position.coords.longitude;
console.log(`${userLatitude} ${userLongitude}`);
});
And different places in 'objects', for example:
var place1= {
name: 'place1',
latitude: '-20',
longitude: '-30'
}
var place2= {
name: 'place2',
latitude: '-30',
longitude: '-19'
}
I need a function or something to get what is the closest place based on my location. Thanks!