Get a Maps Demo Key: Try out select Maps JavaScript API and Places UI Kit features at no cost with a Maps Demo Key—no billing information required.

Promises

  • 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.

Asynchronous methods throughout Google Maps JavaScript API return Promises.

Support

API Methods return Promises
Directions Yes
Distance Matrix Yes
Elevation Yes
Geocoder Yes
Maximum Zoom Imagery Yes
Places No
Places AutocompleteService Partial1
Streetview Yes

Usage

See this guide on using Promises or the examples below for making asynchronous method calls with Google Maps JavaScript API.

Async and await

The await operator is used to wait for a Promise. It can only be used inside an async function.

constapp=async()=>{
constelevationService=google.maps.ElevationService();
constlocations=[{lat:27.986065,lng:86.922623}];
constresponse=awaitelevationService.getElevationForLocation({locations});
console.log(response.results);
};
app();

Then, catch, and finally

The Promise object has then, catch, and finally methods that take callback functions.

constelevationService=google.maps.ElevationService();
constlocations=[{lat:27.986065,lng:86.922623}];
constpromise=elevationService.getElevationForLocation({locations});
promise
.then((response)=>{
console.log(response.results);
})
.catch((error)=>{
console.log(error);
});
.finally(()=>{
console.log('done');
});

Async callback pattern

The callback pattern is still valid and supported.

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);

  1. Currently Promises are only supported in getPlacePredictions().

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026年09月01日 UTC.