与cordova一起使用Google Map JavaScript库 [英] Using Google Map JavaScript library with cordova

查看:394
本文介绍了与cordova一起使用Google Map JavaScript库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google地图JavaScript API和一个cordova项目,

我正在获取地图,几秒钟后,我得到 RefererNotAllowedMapError for file:///android_asset/www/index.html



我也尝试在开发者控制台上提供此网址,但没有成功。



我试图提供通配符星号



是否有其他方式设置自定义引荐来源或如何解决此问题?



---编辑---



键,我更改为Android API键现在它工作正常。



cordova的值不正确: https://maps.googleapis.com/maps/api/js?key=<browser api key> ;



适合科尔多瓦的价值: https://maps.googleapis.com/maps/ap i / js?key =< android api key>



浏览器API键似乎只在html页面在http url

解决方案

截至2017年5月,该问题已由Google解决。现在你可以使用file:/ referrer与API密钥。您可以在文档中看到以下文本:

file://引用者需要将特殊表示添加到键限制中。在添加到密钥限制之前,file:/部分应该替换为__file_url__。例如,file:// path / to /应格式化为__file_url __ / path / to / *。在启用file:// referers后,建议您定期检查您的使用情况,以确保它符合您的期望



https://developers.google.com/maps/documentation/javascript/ get-api-key#键限制


I am trying to use Google map JavaScript API with a cordova project,

I am getting the map, after few seconds, I am getting RefererNotAllowedMapError for file:///android_asset/www/index.html

I tried to provide this URL on the developer console also, but no luck.

I tried to provide wild card asterisk symbol

Is there any other way to set a custom referrer or how to solve this?

---EDIT---

I was using Browser API key, I changed to Android API key now it works fine.

Wrong Value for cordova: https://maps.googleapis.com/maps/api/js?key=<browser api key>

Proper Value for cordova: https://maps.googleapis.com/maps/api/js?key=<android api key>

Browser API key seems to be only allowed when the html page is executed on a http url

解决方案

As of May 2017, the issue has been solved by Google. Now you can use file:/ referrers with API keys. You can see the following text in the documentation

file:// referers need a special representation to be added to the Key restriction. The "file:/" part should be replaced with "__file_url__" before being added to the Key restriction. For example, "file://path/to/" should be formatted as "__file_url__/path/to/*". After enabling file:// referers, it is recommended you regularly check your usage, to make sure it matches your expectations

https://developers.google.com/maps/documentation/javascript/get-api-key#key-restrictions

这篇关于与cordova一起使用Google Map JavaScript库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆