from within a Google API maps places call, I also need to retreive place coords:
if (status != google.maps.places.PlacesServiceStatus.OK) {
callback(data);
} else {
var geocoder = new google.maps.Geocoder();
}
for (var i = 0; i < predictions.length; i++) {
let coords = geocoder.geocode({
'placeId': predictions[i].place_id,
},
function (responses, status) {
if (status == 'OK') {
var lat = responses[0].geometry.location.lat()
var lng = responses[0].geometry.location.lng()
return (lat + '#' + lng)
//CONSOLE LOG HERE IS WORKING the RETURN NOT
}
});
console.log(coords);
data.results.push({
id: predictions[i].place_id,
text: predictions[i].description,
value: coords,
});
}
unluckily I get "PROMISE" value, rather than coords string one. I can't get the way to return and unwrap the promise :(
can you help me?
tyvm