Currently, I am immersing myself in learning Vue.js and exploring the world of Google Maps and geocoding. My current challenge revolves around translating a location into latitude/longitude results. While my code successfully fetches the desired data from Google, I'm facing an issue with accessing variables outside of the if statement. This has left me feeling a bit puzzled and seeking assistance to further enhance my understanding.
var geocoder = new window.google.maps.Geocoder();
var address = "Dublin";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == window.google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
console.log(latitude) // Correct data is returned
console.log(longitude) // Correct data is returned
this.me = longitude
}
});
console.log(this.me) // Does not return anything!!
console.log(longitude) // Does not return anything!!