R
R
rinaz222020-09-30 09:21:31
JavaScript
rinaz22, 2020-09-30 09:21:31

Why does the response from google maps come, but there is no result in the callback?

Hello! I want to get the coordinates of the city entered by the user. For this I use the google maps api "Geocoding Service" function. The answer from google comes and there are coordinates, but the variable is empty.
Here is the code (taken from documentation):

function geocodeAddress(address) {
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status === "OK") {
  console.log(results[0].geometry.location);
        return results[0].geometry.location;
    } else {
      alert("Geocode was not successful for the following reason: " + status);
    }
  });
}

Result in the console:
5f74226826f71272737926.png
Result in network:
5f74234c26a9c674102056.png

And if I use Marker, then the marker is placed in the right place
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
  map: map,
  position: results[0].geometry.location
});


Why is this happening? How can I get coordinates?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-09-30
@rinaz22

Call functions lat()andlng()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question