Annuncio: a breve su Google Maps Platform saranno disponibili nuovi stili della mappa di base. Questo aggiornamento dello stile della mappa include una nuova tavolozza dei colori predefinita, indicatori modernizzati e miglioramenti alle esperienze e all'usabilità delle mappe. Tutti gli stili di mappa verranno aggiornati automaticamente a marzo 2025. Per ulteriori informazioni sulla disponibilità e su come attivare in anteprima questa funzionalità, consulta Nuovo stile di mappa per Google Maps Platform.
Consulta questa
guida
sullo sfruttamento delle promesse o gli esempi riportati di seguito per effettuare chiamate di metodi asincroni
con l'API Google Maps JavaScript.
Async e await
L'operatore await viene utilizzato per attendere una promessa. Può essere utilizzata solo all'interno di una funzione asincrona.
constelevationService=google.maps.ElevationService();constlocations=[{lat:27.986065,lng:86.922623}];constcallback=(results,status)=>{if(status==='OK'){console.log(results);}else{// handle this case}};elevationService.getElevationForLocation({locations},callback);
Al momento le promesse sono supportate solo in getPlacePredictions(). ↩
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-01-15 UTC."],[[["Asynchronous methods within the Google Maps JavaScript API predominantly return Promises for efficient handling of operations."],["Numerous Google Maps services, including Directions, Distance Matrix, Elevation, Geocoder, and Streetview, utilize Promises in their methods."],["Developers can employ async/await, then/catch/finally, or traditional callbacks to manage asynchronous operations and responses effectively."],["While Places generally do not utilize Promises, the `getPlacePredictions()` method within the Places AutocompleteService does offer partial Promise support."],["Beginning in 2020, all newly introduced APIs within the Google Maps JavaScript API exclusively support Promises for asynchronous operations."]]],[]]