Google Maps v3 API密钥不适用于本地测试 [英] Google Maps v3 API key won't work for local testing

查看:130
本文介绍了Google Maps v3 API密钥不适用于本地测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个API密钥。这是一个浏览器应用程序(带引用程序)的关键。它工作正常,但我没有授权,当我尝试在我的本地开发服务器上使用它时,我使用MAMP和我的本地URL如下所示: http://mysite.dev



在Referers部分我有:

  mysite.com/* 
mysite.dev/*

生产版本(.com)工作正常,所以我很确定我的语法是正确的。但是无论我尝试什么本地版本,我都会收到来自Google的授权错误弹出窗口:


Google禁止在此应用中使用Google Maps API,而
提供的金钥不是有效的Google API密钥,或者它如果您是该应用程序的
所有者,您可以在这里了解如何获取有效密钥

< href =https://developers.google.com/maps/documentation/javascript/tutorial#api_key> https:// developer s.google.com/maps/documentation/javascript/tutorial#api_key


当然有一种方法可以得到这个加工!这是什么?

解决方案

更新

截至2016年6月22日,Google地图V3不再支持无钥匙访问(任何不包含API密钥的请求)。

您可以注册键: https://developers.google.com/maps/documentation/javascript / get-api-key



并将其添加到您的网址:

 < script src =https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEYtype =text / javascript>< / script> 






我的应用程序遇到类似的问题。我使用不带客户端密钥的URL进行测试,并在将代码放入生产服务器之前添加密钥。这是一个解决方案,而不是一个解决方案,我假设您的本地测试用法很低。



测试服务器

 < script type =text / javascript
src =https://maps.googleapis.com/maps/api/js?sensor=SET_TO_TRUE_OR_FALSE >
< / script>

生产服务器

 < script type =text / javascript
src =https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=SET_TO_TRUE_OR_FALSE>
< / script>

网址: https://developers.google.com/maps/documentation/javascript/examples/



如果你检查以下网站并转到基本地图示例,您会发现这些示例不使用密钥。这是地图的v2和v3之间的区别之一,该关键不是强制性的。

 < script src = https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false\"></script> 

请注意,免除Google地图API许可下的密钥。如果您需要跟踪使用情况,则必须至少提供密钥。如果您需要更多流量,则需要提供您的客户ID(Google Maps for Work)。



https://developers.google.com/maps/licensing


I have an API key. It's a "Key for browser apps (with referers). It works fine, but I'm not authorized when I try to use it on my local development server. I use MAMP and my local URL looks like this: http://mysite.dev.

In "Referers" section I have:

mysite.com/*
mysite.dev/*

The production one (.com) works fine, so I'm pretty sure my syntax is correct. But no matter what I try for the local version, I get the authorization error popup from Google telling me:

Google has disabled use of the Maps API for this application. The provided key is not a valid Google API Key, or it is not authorized for the Google Maps Javascript API v3 on this site. If you are the owner of this application, you can learn about obtaining a valid key here: https://developers.google.com/maps/documentation/javascript/tutorial#api_key

Surely there is a way to get this working! What is it?

解决方案

UPDATE :

As of June 22, 2016 Google Maps V3 no longer support keyless access (any request that doesn't include an API key).

You can register for the key : https://developers.google.com/maps/documentation/javascript/get-api-key

and add it to your URL :

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" type="text/javascript"></script>


I have faced a similar issue with my application. I use the url without the client key for testing purposes and add the key before putting the code onto the production server. This is a workaround more than a solution and I am assuming that your usage for local testing will be low.

Testing server

<script type="text/javascript" 
   src="https://maps.googleapis.com/maps/api/js?sensor=SET_TO_TRUE_OR_FALSE">
</script>

Production Server

<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=SET_TO_TRUE_OR_FALSE">
</script>

URL : https://developers.google.com/maps/documentation/javascript/examples/

If you check the following site and go to the basic map example you will find that the examples do not use a key. This was one of the differences between v2 and v3 of the maps that the key is not mandatory.

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

Keep in mind that omitting the key falls under the free Google Maps API licensing. If you need to track usage, you must supply at least the key. If you need more traffic, you need to supply your client ID (Google Maps for Work).

https://developers.google.com/maps/licensing

这篇关于Google Maps v3 API密钥不适用于本地测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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