API 金鑰是以專案為主的憑證,應將其視為使用者 ID 和密碼,採取同等的安全防範措施。請詳閱 API 安全性最佳做法,避免因不小心誤用金鑰而不當耗用配額,導致帳戶產生非預期的費用。
使用 API 金鑰存取 Maps API
我們建議以 API 金鑰做為存取 Google Maps API 時的驗證方式。雖然我們仍支援使用用戶端 ID,但 API 金鑰能提供更精細的安全控管機制,且可搭配特定網址、IP 位址和 Mobile SDK (Android 和 iOS) 使用。如要瞭解如何建立及保護 API 金鑰,請前往各個 API 或 SDK 的「使用 API 金鑰」頁面 (例如,針對 Maps JavaScript API,請前往其「使用 API 金鑰」頁面)。
成效
採用指數輪詢策略來處理錯誤
如果您的應用程式在短時間內嘗試呼叫 API 的次數過多,導致發生錯誤 (例如配額錯誤),不妨採用指數輪詢,以便系統處理要求。
您可進行最佳化處理來將多個標記算繪為單一靜態元素,藉此提升效能;這個做法在需要使用大量標記時相當實用。根據預設,Maps JavaScript API 會決定是否對標記進行最佳化處理;若有大量標記,Maps JavaScript API 會嘗試在算繪標記時進行最佳化。不過,並不是所有的標記都能最佳化;在某些情況下,Maps JavaScript API 可能需要以不經最佳化處理的方式算繪標記。若您使用 GIF 動畫或 PNG 圖片,或是每一個標記都必須算繪成個別 DOM 元素,請停用最佳化算繪。
[[["容易理解","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-03-21 (世界標準時間)。"],[[["This guide provides strategies for optimizing Google Maps APIs usage, focusing on security, performance, and cost management."],["Secure your API keys by reviewing security best practices and using them as the preferred authentication method."],["Improve performance by utilizing techniques like exponential backoff for error handling, sending user-interaction requests on demand, and optimizing marker display."],["Manage costs by setting budget alerts, capping daily API usage, and strategically using different Google Maps Platform products based on your needs."],["Understand Google Maps Platform quotas and how they apply to your API usage to avoid unexpected limitations."]]],["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"]]