تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يصف هذا الدليل العديد من الاستراتيجيات لتحسين استخدامك لواجهات برمجة التطبيقات في "خرائط Google" من حيث الأمان والأداء والاستهلاك.
الأمان
مراجعة أفضل ممارسات الأمان
مفاتيح واجهة برمجة التطبيقات هي بيانات اعتماد خاصة بالمشاريع وتستحق اتّخاذ الاحتياطات نفسها التي تتّخذها مع معرّفات المستخدمين وكلمات المرور. راجِع أفضل الممارسات المتعلّقة بأمان واجهات برمجة التطبيقات لحماية مفاتيحك من الاستخدام غير المقصود الذي قد يؤدي إلى استخدام الحصة بشكل غير مبرّر وفرض رسوم غير متوقّعة على حسابك.
استخدام مفاتيح واجهة برمجة التطبيقات للوصول إلى واجهات برمجة التطبيقات في "خرائط Google"
مفاتيح واجهة برمجة التطبيقات هي طريقة المصادقة المفضّلة للوصول إلى واجهات برمجة التطبيقات في "خرائط Google". على الرغم من أنّ استخدام معرّفات العملاء لا يزال متاحًا، تتيح مفاتيح واجهة برمجة التطبيقات عناصر تحكّم أكثر دقة في الأمان ويمكن ضبطها للعمل مع عناوين ويب وعناوين IP وحِزم تطوير البرامج (SDK) للأجهزة الجوّالة (Android وiOS) محدّدة. للحصول على معلومات حول إنشاء مفتاح واجهة برمجة تطبيقات وتأمينه، انتقِل إلى صفحة "استخدام مفتاح واجهة برمجة تطبيقات" لكل واجهة برمجة تطبيقات أو حزمة تطوير برامج. (على سبيل المثال، بالنسبة إلى Maps JavaScript API، انتقِل إلى صفحتها حول استخدام مفتاح API).
الأداء
استخدام خوارزمية الرقود الأسي الثنائي للتعامل مع الأخطاء
إذا واجهت تطبيقاتك أخطاءً بسبب محاولات مفرطة لاستدعاء واجهة برمجة تطبيقات خلال فترة زمنية قصيرة، مثل أخطاء الحصة، ننصحك باستخدام التراجع الأسي للسماح بمعالجة الطلبات.
تكون استراتيجية "التمهّل بين عمليات إعادة المحاولة" مفيدة بشكل خاص للأخطاء التي تبدأ بالرقم 500.
على وجه التحديد، عدِّل وتيرة طلبات البحث. في الرمز، أضِف فترة انتظار تبلغ S ثانية بين طلبات البحث. إذا استمر ظهور خطأ الحصة بعد ذلك، ضاعِف فترة الانتظار ثم أرسِل طلب بحث آخر. واصِل تعديل فترة الانتظار إلى أن يعرض الاستعلام النتائج بدون حدوث خطأ.
إرسال طلبات تفاعل المستخدم عند الطلب
يجب إرسال الطلبات إلى واجهات برمجة التطبيقات التي تتضمّن تفاعلاً من المستخدم عند الطلب فقط.
وهذا يعني انتظار المستخدم النهائي لتنفيذ إجراء (مثل on-click)
لبدء طلب البيانات من واجهة برمجة التطبيقات، ثم استخدام النتائج لتحميل خريطة أو تحديد
وجهة أو عرض المعلومات المناسبة. يؤدي استخدام أسلوب عند الطلب إلى تجنُّب الطلبات غير الضرورية من واجهات برمجة التطبيقات، ما يقلّل من استهلاك واجهة برمجة التطبيقات.
تجنُّب عرض محتوى متراكب عند تحرُّك الخريطة
تجنَّب استخدام Draw() لعرض محتوى تراكب مخصّص على خريطة في الوقت نفسه الذي قد ينقل فيه المستخدم الخريطة. بما أنّ الخريطة تتم إعادة رسمها في كل مرة ينقل فيها المستخدم الخريطة، فإنّ وضع محتوى متراكب على الخريطة في الوقت نفسه قد يؤدي إلى تأخير أو تقطّع مرئي. لا تُضِف محتوى متراكبًا أو تُزِله من خريطة إلا بعد أن يتوقف المستخدم عن تحريك الخريطة أو تكبيرها أو تصغيرها.
تجنُّب العمليات المكثّفة في طرق Draw
كقاعدة عامة، من الممارسات الجيدة تجنُّب العمليات غير المتعلقة بالرسم والتي تتطلّب أداءً عاليًا في طريقة Draw(). على سبيل المثال، تجنَّب ما يلي في رمز طريقة Draw():
الاستعلامات التي تعرض كمية كبيرة من المحتوى
تغييرات كثيرة على البيانات المعروضة
التلاعب بالعديد من عناصر نموذج تمثيل المستندات (DOM)
يمكن أن تؤدي هذه العمليات إلى إبطاء الأداء وحدوث تأخير أو تقطّع مرئي
عند عرض الخريطة.
استخدام صور نقطية للعلامات
استخدِم صورًا نقطية، مثل الصور بتنسيق PNG .أو JPG.، عند إضافة علامات لتحديد موقع جغرافي على خريطة. تجنَّب استخدام صور Scalable Vector Graphics (SVG)، لأنّ عرض صور SVG قد يؤدي إلى حدوث تأخير عند إعادة رسم الخريطة.
تحسين العلامات
تعمل ميزة التحسين على تحسين الأداء من خلال عرض العديد من العلامات كعنصر ثابت واحد. ويكون ذلك مفيدًا في الحالات التي تتطلّب عددًا كبيرًا من العلامات.
تحدّد Maps JavaScript API تلقائيًا ما إذا كان سيتم تحسين العلامة. عندما يكون هناك عدد كبير من العلامات، ستحاول واجهة برمجة التطبيقات JavaScript API في "خرائط Google" عرض العلامات مع تحسينها. لا يمكن تحسين جميع العلامات، ففي بعض الحالات، قد تحتاج Maps JavaScript API إلى عرض العلامات بدون تحسين. إيقاف العرض المحسّن لصور GIF أو PNG المتحركة، أو عندما يجب عرض كل علامة كعنصر DOM منفصل
إنشاء مجموعات لإدارة عرض العلامات
للمساعدة في إدارة عرض العلامات لتحديد المواقع الجغرافية على الخريطة، يمكنك إنشاء مجموعة علامات باستخدام مكتبة Marker Clusterer.
تتضمّن مكتبة Marker Clusterer خيارات لما يلي:
حجم الشبكة لتحديد عدد العلامات التي سيتم تجميعها معًا
في مجموعة
الحد الأقصى للتكبير، لتحديد الحد الأقصى لمستوى التكبير الذي سيتم عرض المجموعة فيه
مسارات الصور، لصور الرسومات التي سيتم استخدامها كرموز محدّدة
مشاهدة المحتوى
للحصول على معلومات حول إدارة تكاليف Google Maps Platform، بما في ذلك إنشاء الميزانيات وتعديل الحصص وتعيين التنبيهات، يُرجى الاطّلاع على إدارة التكاليف.
تاريخ التعديل الأخير: 2025-09-05 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-09-05 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis guide provides strategies for optimizing Google Maps APIs usage, focusing on security, performance, and cost management.\u003c/p\u003e\n"],["\u003cp\u003eSecure your API keys by reviewing security best practices and using them as the preferred authentication method.\u003c/p\u003e\n"],["\u003cp\u003eImprove performance by utilizing techniques like exponential backoff for error handling, sending user-interaction requests on demand, and optimizing marker display.\u003c/p\u003e\n"],["\u003cp\u003eManage costs by setting budget alerts, capping daily API usage, and strategically using different Google Maps Platform products based on your needs.\u003c/p\u003e\n"],["\u003cp\u003eUnderstand Google Maps Platform quotas and how they apply to your API usage to avoid unexpected limitations.\u003c/p\u003e\n"]]],["Optimize Google Maps APIs usage by securing API keys, using them instead of client IDs, and implementing exponential backoff for errors. Enhance performance by sending requests on demand, avoiding overlays during map movement, using raster images for markers, and optimizing/clustering markers. Control consumption by setting budget alerts, capping daily usage, using static images when user interaction isn't needed, using the embed API for basic maps, and using mobile SDKs for mobile. In addition, you can reduce costs with optimized routing, limited waypoints, and cost-effective autocomplete and geocoding options.\n"],null,["# Optimization Guide\n\nThis guide describes several strategies to optimize your Google Maps APIs\nusage in terms of security, performance, and consumption.\n\nSecurity\n--------\n\n### Reviewing security best practices\n\nAPI keys are project-centric credentials that deserve the same precautions\nas user IDs and passwords. Review the\n[API Security Best Practices](/maps/api-security-best-practices) to secure your keys from\nunintended use which could lead to undue quota usage and unexpected charges\nto your account.\n\n### Using API keys to access Maps APIs\n\nAPI keys are the preferred authentication method for accessing\nGoogle Maps APIs. While using the client IDs is still\nsupported, API keys support finer-grained security controls and can be tuned to\nwork with specific web addresses, IP addresses, and mobile SDKs (Android and\niOS). For information on creating and securing an API key, go to the \"Using an\nAPI Key\" page for each API or SDK. (For example, for the\nMaps JavaScript API, visit its page on [Using an API\nKey](/maps/documentation/javascript/get-api-key).)\n\nPerformance\n-----------\n\n### Using exponential backoff to handle errors\n\nIf your apps experience errors from excessive attempts to call an API\nwithin a short period of time, such as quota errors, consider using\n[exponential backoff](http://en.wikipedia.org/wiki/Exponential_backoff) to let the requests process.\nExponential backoff is most useful for errors in the 500s.\n\nSpecifically, adjust the pace of your queries. In your code, add\na waiting period of **`S`** seconds between queries. If the query still results\nin a quota error, double the waiting period and then send another query. Continue\nadjusting the waiting period until the query returns without an error.\n\n### Sending user-interaction requests on demand\n\nRequests to APIs that include user interaction should be sent only on demand.\nThis means waiting for the end user to perform an action (such as `on-click`)\nto initiate the API request, then using the results to load a map, set a\ndestination, or display appropriate information. Using an on-demand approach\navoids unnecessary requests to the APIs, reducing API consumption.\n\n### Avoiding displaying overlay content when a map is moving\n\nAvoid using `Draw()` to display custom overlay content on a map at the same\ntime that a user might be moving the map. Since the map is redrawn every time\na user moves the map, placing overlay content on the map at the same time can\nintroduce lag or visual stuttering. Only add or remove overlay content from a\nmap once the user stops panning or zooming.\n\n### Avoiding intensive operations in `Draw` methods\n\nAs a general rule, it is good practice to avoid performance-intensive\nnon-drawing operations in a `Draw()` method. For example, avoid\nthe following in your `Draw()` method code:\n\n- Queries that return a large amount of content.\n- Many changes to the data being displayed.\n- Manipulating many Document Object Model (DOM) elements.\n\nThese operations can slow performance and introduce lag or visual stuttering\nwhen the map renders.\n\n### Using raster images for markers\n\nUse raster images, such as images in .PNG or .JPG format, when adding\nmarkers to identify a location on a map. Avoid using Scalable Vector\nGraphics (SVG) images, since rendering SVG images can introduce lag when\nthe map is redrawn.\n\n### Optimizing markers\n\nOptimization enhances performance by rendering many markers as a single static\nelement. This is useful in cases where a large number of markers is required.\nBy default, the Maps JavaScript API will decide whether a marker\nwill be optimized. When there is a large number of markers, the\nMaps JavaScript API will attempt to render markers with\noptimization. Not all Markers can be optimized; in some situations, the\nMaps JavaScript API may need to render Markers without\noptimization. Disable optimized rendering for animated GIFs or PNGs, or when\neach marker must be rendered as a separate DOM element.\n\n### Creating clusters to manage marker display\n\nTo help manage the display of markers to identify locations on a map,\ncreate a marker cluster using the\n[Marker Clusterer](https://github.com/googlemaps/js-marker-clusterer) library.\nThe Marker Clusterer library includes options for:\n\n- Grid size, to specify the number of markers to group together in a cluster.\n- Maximum zoom, to specify the maximum zoom level in which to display the cluster.\n- Image paths, for the graphics images to use as marker icons.\n\nConsumption\n-----------\n\nFor information on managing your Google Maps Platform costs, including\ncreating budgets, modifying quotas, and setting alerts, see\n[Manage costs](/maps/billing-and-pricing/manage-costs)."]]