Ogłoszenie: wkrótce w Google Maps Platform pojawi się nowy styl mapy podstawowej. Ta aktualizacja stylizacji mapy obejmuje nową domyślną paletę kolorów, ulepszone piny oraz udoskonalenia dotyczące użyteczności i wygody korzystania z map. Wszystkie style map zostaną automatycznie zaktualizowane w marcu 2025 r. Więcej informacji o dostępności i o tym, jak wcześniej włączyć tę funkcję, znajdziesz w artykule Nowy styl map w Google Maps Platform.
Zapoznaj się z tym przewodnikiem na temat korzystania z obietnic lub z przykładami poniżej, aby wykonywać asynchroniczne wywołania metod za pomocą interfejsu Maps JavaScript API.
Async i await
Operator await służy do oczekiwania na obietnicę. Może być używana tylko w ramach funkcji asynchronicznej.
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);
Obecnie obietnice są obsługiwane tylko w języku getPlacePredictions(). ↩
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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."]]],[]]