1
var location
var point = new google.maps.LatLng(data[key].latitude, data[key].longitude);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
  latLng: point
}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    if (results[0]) {
      location = results[0].formatted_address;
    }
  }
});

console.log(location);

when i console variable location is undefined outside of geocode function
here location is undefined. inside geocode i am getting location value.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I recommend cleaning up your question if possible. If I am reading this right you're wondering why `location` is `undefined` in your console logs? – Pixxl Dec 08 '18 at 05:19
  • @Pixxl check now –  Dec 08 '18 at 05:42
  • Have you tried debugging the response first? Such as `console.log({status:status, results:results}` ... My first assumption is that one or both of your logic `if` statements are not evaluating to true. – Pixxl Dec 08 '18 at 06:01
  • @Pixxl when i console status and result i am getting results: null ​ status: "OVER_QUERY_LIMIT" –  Dec 08 '18 at 06:21
  • Okay so "OVER_QUERY_LIMIT" would probably not be a status of OK. You should consult the API documentation. You've likely hit some sort of attempt or call quota – Pixxl Dec 08 '18 at 18:58

0 Answers0