Javascript 如何在谷歌地图api中为本地主机提供推荐网址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38006171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to give referrer url for localhost in google map api?
提问by vikash
I am using google map geocode api for getting city,country,and state from zip code. I have restricted the API key to only respond to requests from allowed URLs.
我正在使用谷歌地图地理编码 api 从邮政编码中获取城市、国家和州。我已将 API 密钥限制为仅响应来自允许 URL 的请求。
It works fine except when I try to give referrer url for localhost it doesn't work. I am getting error "RefererNotAllowedMapError";
它工作正常,除非我尝试为 localhost 提供引荐网址时它不起作用。我收到错误“ RefererNotAllowedMapError”;
I don't understand how to give url for edit because every time the url of edit changes. Please share solutions if there is a way to allow the API to be accessed from localhost.
我不明白如何给 url 进行编辑,因为每次编辑的 url 都会发生变化。如果有办法允许从本地主机访问 API,请分享解决方案。
回答by Bruno Simoes
回答by abielita
Try to create an API key again. I would suggest you to follow Get a Key/Authentication.
再次尝试创建 API 密钥。我建议您遵循获取密钥/身份验证。
NOTE:
笔记:
Google Maps APIs are available for Android or iOS apps, Web browsers, and via HTTP web services. APIs in each platform require a specific type of key. The Google Maps JavaScript API will only work with a Browser key. APIs of the same platform can use the same key.
Google Maps API 可用于 Android 或 iOS 应用程序、Web 浏览器以及通过 HTTP Web 服务。每个平台中的 API 都需要特定类型的密钥。Google Maps JavaScript API 只能使用浏览器键。同一平台的 API 可以使用相同的密钥。
Also, check Registering authorized URLsto validate if you are entering a correct format URL.
此外,检查注册授权 URL以验证您输入的 URL 格式是否正确。
For example:
例如:
http://localhost
or http://localhost:[PORT_NUMBER]
http://localhost
或者 http://localhost:[PORT_NUMBER]
Hope this helps!
希望这可以帮助!
回答by Alfred Wallace
localhost:52200/*
worked for me in July 2019. Didn't need explicit protocol like http
or https
.
localhost:52200/*
2019 年 7 月为我工作。不需要像http
或 之类的显式协议https
。
回答by user2188850
http://localhost
wasn't enough for me, but adding an asterisk worked: http://localhost/*
http://localhost
对我来说还不够,但添加星号有效: http://localhost/*