Пробовал вот в этом примере:
http://95.174.111.242:8091/maptest/test.php
Полный код данной тестовой странички:
<html>
<head>
<title>Geocode example</title>
</head>
<body>
<p>map</p>
<style>
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?key=key"></script>
<div id="map_canvas" style="border: 2px solid #3872ac;"></div>
<script>
var geocoder;
var map;
var bounds = new google.maps.LatLngBounds();
function initialize() {
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(41.92233950111221, 12.442120355172237),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
initialize();
function asyncGeocode(params) {
alert('asyncGeocode started with params: '+params);
return new Promise((resolve, reject) => geocoder.geocode(
params,
(results, status) => status === 'OK' ? resolve(results) : reject(status)
));
}
async function addressToCoords(loc) {
var address = loc;
var result = await asyncGeocode(address).catch(status => {
console.log('Error: ' + status);
return '';
});
alert('now here');
alert('Result is ' + result);
return result;
}
addressToCoords('Rome, Italy').then (coords => alert(coords));
alert(result);
</script>
</body>
</html>
Должен сработать
alert('Result is ' + result);
однако его не вижу