Pushing getCurrentPosition() values into array but cannot console log elements of the array
up vote
0
down vote
favorite
I've wrapped the geolocation API in the getLocation() function and am returning an array. However, when I try to access the specific elements of the array, I am getting undefined. I feel like I'm missing something very simple here. const getLocation = function () { const arrLocations = ; navigator.geolocation.getCurrentPosition(function (position) { arrLocations.push(position.coords.latitude) arrLocations.push(position.coords.longitude) }); return arrLocations; } const coord = getLocation(); console.log(coord); console.log(coord[0]); I've also tried to wrap the geolocation in a promise just in case there is some async happening with getCurrentPosition. The call returns undefined. (I'm not sure if I