您可以通过Google AJAX API加载器加载Google Maps API v3吗? [英] Can you load Google Maps API v3 via Google AJAX API loader

查看:92
本文介绍了您可以通过Google AJAX API加载器加载Google Maps API v3吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间,我使用了像这样加载Google Maps API的常规方法:

Some time ago I used the regular method of loading Google Maps API like this:

<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=true">

稍后,我切换到Google AJAX API以加载Google Maps API。这是因为我网站上的一些小工具需要Google Ajax API加载程序,所以我选择了一致并使用AJAX API加载Google地图:

Later I switched to Google AJAX APIs to load Google Maps API. This was because a couple of "widgets" on my website needed the Google Ajax API loader so I chose to be consistent and used the AJAX APIs to load Google Maps as well:

<script type="text/javascript" src="http://www.google.com/jsapi?key=abcdef"></script>
<script type="text/javascript">
  google.load("maps", "2", {"other_params": "sensor=true"});
</script>

现在我终于决定使用Google Maps API v3,此页面未列出可用版本列表中的API v3。 API v3文档中的示例也没有显示使用AJAX API。是否可以(并支持)通过AJAX API加载器加载Google Maps API v3?

Now that I have finally decided to use Google Maps API v3, this page does not list API v3 in the available version list. None of the examples on API v3 documentation show the use of AJAX APIs as well. Is is possible (and supported) to load Google Maps API v3 via AJAX API loader?

推荐答案

它没有记录,但是可行。

It's undocumented, but it works.

google.load("maps", "3", {other_params:'key=YOUR_API_KEY', callback: function(){
  var map; // initialize your map in here
}});


现在文档需要使用传递给加载器作为关键参数。我删除了'sensor = false'作为参数,因为它现在显式不是必需的,并且在提供时会引发警告。

The documentation now requires the use of an API key that is passed to the loader as a "key" parameter. I've removed 'sensor=false' as a parameter because it is now explicitly not required and throws a warning when provided.

这篇关于您可以通过Google AJAX API加载器加载Google Maps API v3吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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