0

When I run the function getCoordinates and console.log the two variables I want, the function works as planned and shows: 30.4190671 -97.74594990000003 in the console. Here is the wowrking code...

getCoordinates("5401 Duval Austin TX")

function getCoordinates (address) {
    geocoder = new google.maps.Geocoder();
    var coordinatesA;
    var coordinatesB;
    geocoder.geocode({ address: address}, function (results, status) {
    coordinatesA = results[0].geometry.location.lat()
    coordinatesB = results[0].geometry.location.lng()
    console.log(coordinatesA, coordinatesB)
    })
};

However, when I add the return line at the end of the function in order to work with the data. And I console.log(getCoordinates("5401 Duval Austin TX")) I get undefined here is the full code block:

console.log(getCoordinates("5401 Duval Austin TX"))

function getCoordinates (address) {
    geocoder = new google.maps.Geocoder();
    var coordinatesA;
    var coordinatesB;
    geocoder.geocode({ address: address}, function (results, status) {
    coordinatesA = results[0].geometry.location.lat()
    coordinatesB = results[0].geometry.location.lng()
    return coordinatesA + coordinatesB
    })
};

What gives?

Adam Weitzman
  • 1,402
  • 4
  • 17
  • 43

0 Answers0