Ankündigung:Auf der Google Maps Platform ist bald eine neue Version der Funktionen für das cloudbasierte Gestalten von Karteninhalten verfügbar. Die Aktualisierung umfasst eine neue Standardfarbvorlage, modernisierte Markierungen und Verbesserungen in Bezug auf die Nutzerfreundlichkeit der Karten. Alle Kartenstile werden im März 2025 automatisch aktualisiert. Weitere Informationen zur Verfügbarkeit und Aktivierung sind unter Neuer Kartenstil für die Google Maps Platform verfügbar.
In diesem Leitfaden erfahren Sie, wie Sie Promise-Objekte oder die nachfolgenden Beispiele verwenden, um mit der Google Maps JavaScript API asynchrone Methodenaufrufe auszuführen.
„async“ und „await“
Der Operator „await“ wird verwendet, um auf ein Promise-Objekt zu warten. Seine Verwendung ist nur in asynchronen Funktionen möglich.
Das Callback-Muster ist weiterhin gültig und wird unterstützt.
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);
Promise-Objekte werden derzeit nur in getPlacePredictions() unterstützt. ↩
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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."]]],[]]