Google Maps JavaScript API'deki eşzamansız yöntemler Vaatler değerini döndürür.
Destek
API | Vaat edilen yöntemler |
---|---|
Yol tarifi | Evet |
Mesafe Matrisi | Evet |
Rakım | Evet |
Coğrafi Kodlayıcı | Evet |
Maksimum Yakınlaştırma Görüntüleri | Evet |
Yerler | Hayır |
Yerler Otomatik Tamamlama Hizmeti | Kısmi1 |
Street View | Evet |
Kullanım
Vaat kullanımı hakkında bilgi için bu kılavuza veya Google Maps JavaScript API ile eşzamansız yöntem çağrıları yapmak için aşağıdaki örneklere bakın.
Eş zamansız ve bekle
Bekleme operatörü, Vakı beklemek için kullanılır. Yalnızca eşzamansız işlevlerin içinde kullanılabilir.
const app = async () => {
const elevationService = google.maps.ElevationService();
const locations = [{lat: 27.986065, lng:86.922623}];
const response = await elevationService.getElevationForLocation({locations});
console.log(response.results);
};
app();
Son olarak,
Promia nesnesi, geri çağırma işlevlerini alan then
, catch
ve finally
yöntemlerine sahiptir.
const elevationService = google.maps.ElevationService();
const locations = [{lat: 27.986065, lng:86.922623}];
const promise = elevationService.getElevationForLocation({locations});
promise
.then((response) => {
console.log(response.results);
})
.catch((error) => {
console.log(error);
});
.finally(() => {
console.log('done');
});
Eşzamansız geri çağırma kalıbı
Geri çağırma kalıbı geçerli olmaya ve desteklenmeye devam eder.
const elevationService = google.maps.ElevationService();
const locations = [{lat: 27.986065, lng:86.922623}];
const callback = (results, status) => {
if (status === 'OK') {
console.log(results);
} else {
// handle this case
}
};
elevationService.getElevationForLocation({locations}, callback);
-
Şu anda taahhütler yalnızca
getPlacePredictions()
bölgesinde desteklenmektedir. ↩