如何使用不带API密钥的谷歌地图 [英] How to use google maps without api key

查看:174
本文介绍了如何使用不带API密钥的谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用此代码在Google地图中使用获取方向。但是当我从其他机器运行它显示错误无效api键。

 < script src =http://maps.google.com ?/映射文件= API&放大器;放大器; v = 2及安培;传感器=假放大器;放大器;键= ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw类型= 文本/ JavaScript的 >< /脚本> 
< style type =text / css>
body {
背景:#FFE1C7;
font-family:Verdana,Arial,sans serif;
font-size:11px;
margin:2px;
}
table.directions th {
background-color:#EEEEEE;
}

img {
color:#000000;
}
< / style>
< script type =text / javascript>

var map;
var gdir;
var geocoder = null;
var addressMarker;

函数initialize(){
if(GBrowserIsCompatible()){
map = new GMap2(document.getElementById(map_canvas));
gdir = new GDirections(map,document.getElementById(directions));
GEvent.addListener(gdir,load,onGDirectionsLoad);
GEvent.addListener(gdir,error,handleErrors);

setDirections(Bangalore,Mysore,en_US);



函数setDirections(fromAddress,toAddress,locale){
gdir.load(from:+ fromAddress +to:+ toAddress,
{locale:locale});


函数handleErrors(){
if(gdir.getStatus()。code == G_GEO_UNKNOWN_ADDRESS)
alert(没有相应的地理位置可以找到指定的地址之一,这可能是由于地址相对较新,或者可能不正确。\\\
错误代码:+ gdir.getStatus()。code);
else if(gdir.getStatus()。code == G_GEO_SERVER_ERROR)
alert(地理编码或指导请求无法成功处理,但失败的确切原因尚不清楚。\\\
错误代码:+ gdir.getStatus()。code);

else if(gdir.getStatus()。code == G_GEO_MISSING_QUERY)
alert(HTTP q参数缺失或没有值。对于geocoder请求,这意味着一个空地址被指定为输入,对于指示请求,这意味着在输入中没有指定查询。\\\
错误代码:+ gdir.getStatus()。code);

// else if(gdir.getStatus()。code == G_UNAVAILABLE_ADDRESS)< --- Doc bug ...这是要么没有定义,要么Doc是错的
// alert(给定地址的地理编码或给定方向查询的路由由于法律或合同原因而无法返回。\\\
错误代码:+ gdir.getStatus()。code);

else if(gdir.getStatus()。code == G_GEO_BAD_KEY)
alert(给定的键无效或与给定的键不匹配。\\\
错误代码:+ gdir.getStatus()。code);

else if(gdir.getStatus()。code == G_GEO_BAD_REQUEST)
alert(指示请求无法成功解析。错误代码:+ gdir.getStatus( )。码);

else alert(发生未知错误。);
}

函数onGDirectionsLoad(){
//使用此函数访问有关最新加载()
//结果的信息。

//例如
// document.getElementById(getStatus)。innerHTML = gdir.getStatus()。code;
//和yada yada yada ...
}

< / script>

任何人都可以帮助我...提前致谢..
<您需要将API从V2更改为V3,因为Google地图版本3不需要API密钥



请查看 out ..



将您的脚本编写为

 < script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>< / script> 

编辑:此答案现在已过期。您现在需要有一个API密钥才能使用Google地图。请参阅下面的评论。


Hi i am using this code to use get-directions in google maps. but when i run this from other machines it is showing the error invalid api key. how to use this same map without an api key.

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
    <style type="text/css">
    body {
      background:#FFE1C7;
      font-family: Verdana, Arial, sans serif;
      font-size: 11px;
      margin: 2px;
    }
table.directions th {
      background-color:#EEEEEE;
    }

    img {
      color: #000000;
    }
    </style>
    <script type="text/javascript">

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        setDirections("Bangalore", "Mysore", "en_US");
      }
    }

    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
     if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
       alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
     else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
       alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

     else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
       alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

    //   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
    //     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);

     else if (gdir.getStatus().code == G_GEO_BAD_KEY)
       alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

     else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
       alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

     else alert("An unknown error occurred.");
    }

    function onGDirectionsLoad(){
        // Use this function to access information about the latest load()
        // results.

        // e.g.
        // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
      // and yada yada yada...
    }

    </script>

Can anyone help me...thanks in advance..

解决方案

you need to change your API from V2 to V3, Since Google Map Version 3 don't required API Key

Check this out..

write your script as

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

EDIT: This answer is now out-of-date. You are now required to have an API key to use google maps. See comments below.

这篇关于如何使用不带API密钥的谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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