最適化ガイド
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このガイドでは、セキュリティ、パフォーマンス、消費の観点から、Google Maps API の使用量を最適化するための複数の戦略について説明します。
セキュリティ
セキュリティに関するベスト プラクティスを確認する
API キーはプロジェクト主導型の認証情報で、ユーザー ID やパスワードと同じように取り扱いに注意を要するものです。目的外の使用によりアカウントの割り当てを不当に消費してしまい、不測の請求を受けることのないように、API セキュリティに関するベスト プラクティスを確認してください。
API キーを使用して Maps API にアクセスする
API キーは、Google Maps API へのアクセス用の推奨の認証方式です。クライアント ID もまだサポートされていますが、API キーはきめ細かいセキュリティ管理に対応しており、特定のウェブアドレス、IP アドレス、モバイル SDK(Android および iOS)と連携させることもできます。API キーの作成と保護について詳しくは、各 API または SDK の [API キーを使用する] ページをご参照ください(たとえば、Maps JavaScript API については、該当する API キーを使用するをご参照ください)。
指数バックオフを使用してエラー処理を行う
割り当てエラーなど、短時間の過剰な API 呼び出しによりエラーが発生する場合は、リクエストの処理に指数バックオフを使用することをおすすめします。指数バックオフは、500 番台のエラーに対して最も効果的です。
指数バックオフとは、具体的に説明すると、クエリの送信ペースの調整です。コードで、クエリ間の待機時間として S
秒追加します。それでもクエリの際に割り当てエラーが繰り返される場合は、待機期間を 2 倍にしてから別のクエリを送信します。クエリがエラーなしで返されるまで、待機時間を調整していきます。
ユーザー操作リクエストをオンデマンドで送信する
ユーザー操作を含む API へのリクエストは、オンデマンドでのみ送信する必要があります。つまり、エンドユーザーが API リクエストを開始する操作(on-click
など)を実行するまで待機してから、その結果を使用して地図の読み込み、目的地の設定、適切な情報の表示を行います。オンデマンド送信により API に対する不要なリクエストを回避して、API の消費を減らすことができます。
地図を動かしているときにオーバーレイ コンテンツが表示されないようにする
ユーザーが地図を移動する可能性がある状況で、Draw()
を使用してカスタム オーバーレイ コンテンツを表示することは避けます。ユーザーが動かすたびに地図が再描画されるため、移動の最中にオーバーレイ コンテンツを配置しようとすると、遅延やスタッタリング(視覚的な途切れ)が生じる可能性があります。ユーザーが地図のパンやズームを停止してから、オーバーレイ コンテンツを追加または削除します。
Draw
メソッドで負荷の大きいオペレーションを回避する
一般的に、Draw()
メソッドでは、負荷の大きい非描画オペレーションを回避することをおすすめします。たとえば、Draw()
メソッドのコードでは、次のことは避けてください。
- 大量のコンテンツを返すクエリ
- 表示されるデータの大幅な変更
- 多数のドキュメント オブジェクト モデル(DOM)要素の操作
このようなオペレーションでは、地図のレンダリング時にパフォーマンスが低下し、遅延やスタッタリングが生じることがあります。
マーカーにラスター画像を使用する
マーカーを追加して地図上の場所を識別する際に、.PNG 形式または .JPG 形式の画像などのラスター画像を使用します。Scalable Vector Graphics(SVG)画像は使用しないでください。SVG 画像をレンダリングすると、地図が再描画される際に遅延が発生する場合があります。
マーカーを最適化する
最適化すると、多数のマーカーが単一の静的要素としてレンダリングされ、パフォーマンスが向上します。最適化は、多くのマーカーが必要な場合に便利です。デフォルトでは、マーカーの最適化を行うかどうかを Maps JavaScript API が判断します。マーカーが多数ある場合、Maps JavaScript API はマーカーを最適化してレンダリングを試みます。ただし、すべてのマーカーを最適化できるわけではなく、最適化せずにレンダリングしなければならない場合もあります。アニメーション GIF または PNG の場合、または各マーカーを個別の DOM 要素としてレンダリングする必要がある場合、レンダリングの最適化を無効にしてください。
マーカー表示を管理するためにクラスタを作成する
地図上の場所を特定するマーカー表示を管理しやすいように、マーカー クラスタ ライブラリを使用してマーカー クラスタを作成します。マーカー クラスタ ライブラリには、次のオプションがあります。
- グリッドサイズ: クラスタ内でグループ化するマーカーの数。
- 最大ズーム: クラスタを表示する最大ズームレベル。
- マーカー アイコンとして使用するグラフィック画像の画像パス。
消費
予算の作成、割り当ての変更、アラートの設定など、Google Maps Platform の費用を管理する方法については、費用を管理するをご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-05 UTC。
[null,null,["最終更新日 2025-09-05 UTC。"],[[["\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)."]]