在某些情况下,可能会显示暗色地图或“负片”效果的街景图像,并带有“仅用于开发目的”的文字水印。如果出现此行为,通常说明存在 API 密钥或结算方面的问题。为了使用 Google Maps Platform 产品,必须为账号启用结算功能,并且所有请求都必须包含有效的 API 密钥。以下流程有助于排查此问题:
您有使用 API 密钥吗?
我不确定。如何确认我是否使用了 API 密钥?
API 密钥以 key 参数的形式在网址中传递,用于加载 Maps JavaScript API。您可以通过以下几种方法检查您是否使用了 API 密钥:
具有 IP 地址限制的 API 密钥只能用于适合从服务器端使用的网络服务(例如 Geocoding API 和其他网络服务 API)。大部分此类网络服务在 Maps JavaScript API 中都有等效服务(有关示例,请参阅地理编码服务)。如需使用 Maps JavaScript API 客户端服务,您需要单独创建一个可使用 HTTP 引荐来源网址限制进行保护的 API 密钥(请参阅获取、添加和限制 API 密钥)。
如果您的代码不能正常运行:
为帮助您确保地图代码正常运行,Brendan Kenny 和 Mano Marks 在此视频中介绍了一些常见错误及相应解决方法。
[null,null,["最后更新时间 (UTC):2025-02-28。"],[[["To use the Google Maps JavaScript API, you must include an API key and enable billing for your project."],["If you see a darkened map or a negative Street View image watermarked with \"for development purposes only\", you might have an issue with your API key or billing."],["Troubleshooting steps involve verifying your API key implementation, checking billing account attachment, ensuring billing method validity, and reviewing daily usage limits and IP restrictions."],["This page offers solutions to common billing and API errors, and links to resources for further assistance."]]],["Using the Maps JavaScript API requires a valid API key and enabled billing. Issues like a darkened map typically stem from these. Verify API key usage via browser checks, source code, or network traffic. Ensure the project linked to your API key has an active billing account. Check for invalid payment methods or exceeded API daily limits. If restricted by IP address, create a key with HTTP referrers. Troubleshoot by checking for typos, verifying map element properties, or using a JavaScript debugger.\n"]]