Realistically I just want a way to access the latitude and longitude later like a global variable. I came up with this 'solution' if you can call it that. It's been a while since i've done some OOP.
What do I need to do?
var geo = {
local: function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(postition){
latitude: position.coords.latitude;
longitude: position.coords.longitude;
})
}
}
};
function initMap() {
var userLocation = {lat: geo.local.latitude, lng: geo.local.longitude};
var map = new google.maps.Map(document.getElementById('map'), {
zoom:14,
center: userLocation
});
};
console.log(geo.local.longitude);
console.log(geo.local.latitude);
Thanks!