我正在使用Cordova开发一个android应用程序,并且遇到了有关Google Maps JavaScript API的问题。
我们有一个已购买的API,并以以下格式包含它。
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&client=<?php echo MAP_CLIENT; ?>&signature=<?php echo MAP_SIGNATURE; ?>"></script>
使用此特定脚本在Web浏览器中绝对可以正常工作,但显示如下错误。
糟糕!有些不对劲。此页面未加载Google Maps 正确地。请参阅JavaScript控制台以获取技术详细信息
答案 0 :(得分:0)
As you are using the Premium plan with a client
parameter you should authorize the URL you are loading an API from in your Google cloud support portal.
To prevent a third party from using your client ID on their own website, the use of your client ID is restricted to a list of URLs that you specifically authorize.
To see the URLs you have already authorized or to authorize additional URLs:
- Log in to the Google Cloud Support Portal.
- In the left-hand menu, click Maps: Manage Client ID.
You can add up to 100 URLs at a time. A Client ID may be associated with up to 3000 authorized URLs. If you expect your application to host Google Maps content from more than 3000 locations, you should switch to using API keys instead.
source: https://developers.google.com/maps/documentation/javascript/get-api-key#registering-authorized-urls
In order to figure out what is the URL that you should authorize, check the value of the window.location.href
in you hybrid app. This value should be added to the list of authorized URLs.
Also note that Maps JavaScript API doesn't have signature parameter. You must delete it, especially if you expose there your cryptographic key which must be private.
I hope this helps!