reviewsהשקת Places UI Kit: ספריית רכיבים מוכנה לשימוש בעלות נמוכה, שמאפשרת לכם להוסיף לכל מפה שתבחרו את ממשק המשתמש המוכר של 'מקומות' במפות Google. כדאי לנסות אותו ולשלוח לנו משוב כדי לעזור לנו לעצב את העתיד של GMP.
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);
בשלב הזה, יש תמיכה ב-Promises רק בשפות getPlacePredictions(). ↩
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-17 (שעון UTC)."],[[["\u003cp\u003eAsynchronous methods within the Google Maps JavaScript API predominantly return Promises for efficient handling of operations.\u003c/p\u003e\n"],["\u003cp\u003eNumerous Google Maps services, including Directions, Distance Matrix, Elevation, Geocoder, and Streetview, utilize Promises in their methods.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can employ async/await, then/catch/finally, or traditional callbacks to manage asynchronous operations and responses effectively.\u003c/p\u003e\n"],["\u003cp\u003eWhile Places generally do not utilize Promises, the \u003ccode\u003egetPlacePredictions()\u003c/code\u003e method within the Places AutocompleteService does offer partial Promise support.\u003c/p\u003e\n"],["\u003cp\u003eBeginning in 2020, all newly introduced APIs within the Google Maps JavaScript API exclusively support Promises for asynchronous operations.\u003c/p\u003e\n"]]],[],null,["Asynchronous methods throughout Google Maps JavaScript API return\n[Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).\n\nSupport\n\n| API | Methods return Promises |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------|\n| [Directions](/maps/documentation/javascript/directions) | Yes |\n| [Distance Matrix](/maps/documentation/javascript/reference/distance-matrix \"Reference documentation for Distance Matrix service\") | Yes |\n| [Elevation](/maps/documentation/javascript/reference/elevation \"Reference documentation for Elevation service\") | Yes |\n| [Geocoder](/maps/documentation/javascript/reference/geocoder \"Reference documentation for Geocoder service\") | Yes |\n| [Maximum Zoom Imagery](/maps/documentation/javascript/reference/max-zoom \"Reference documentation for MaxZoom service\") | Yes |\n| Places | No |\n| [Places AutocompleteService](/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteService \"Reference documentation for Places Autocomplete service\") | Partial^[1](#fn1)^ |\n| [Streetview](/maps/documentation/javascript/reference/street-view \"Reference documentation for StreetView service\") | Yes |\n\n| **Note:** Starting in 2020, new APIs only support Promises.\n\nUsage \n\nSee this\n[guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_Promises)\non using Promises or the examples below for making asynchronous method calls\nwith Google Maps JavaScript API.\n\nAsync and await\n\nThe\n[await operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)\nis used to wait for a Promise. It can only be used inside an async function. \n\n const app = async () =\u003e {\n const elevationService = google.maps.ElevationService();\n const locations = [{lat: 27.986065, lng:86.922623}];\n\n const response = await elevationService.getElevationForLocation({locations});\n console.log(response.results);\n };\n\n app();\n\nThen, catch, and finally\n\nThe\n[Promise object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Instance_methods)\nhas `then`, `catch`, and `finally` methods that take callback functions. \n\n const elevationService = google.maps.ElevationService();\n const locations = [{lat: 27.986065, lng:86.922623}];\n\n const promise = elevationService.getElevationForLocation({locations});\n\n promise\n .then((response) =\u003e {\n console.log(response.results);\n })\n .catch((error) =\u003e {\n console.log(error);\n });\n .finally(() =\u003e {\n console.log('done');\n });\n\nAsync callback pattern\n\nThe\n[callback pattern](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Introducing#Async_callbacks)\nis still valid and supported. \n\n const elevationService = google.maps.ElevationService();\n const locations = [{lat: 27.986065, lng:86.922623}];\n\n const callback = (results, status) =\u003e {\n if (status === 'OK') {\n console.log(results);\n } else {\n // handle this case\n }\n };\n\n elevationService.getElevationForLocation({locations}, callback);\n\n**Note:** Starting in 2020, new APIs only support Promises. \n\n*** ** * ** ***\n\n1. Currently Promises are only supported in `getPlacePredictions()`. [↩](#fnref1)"]]