`
isiqi
  • 浏览: 16598522 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Google Maps API Concepts——Google 地图 API 文档之一

阅读更多

Google Maps API Concepts

Welcome to the developer documentation for the Google Maps API! The Google Maps JavaScript API lets you embed Google Maps in your web pages. To use the API, you need to first sign up for an API key. Once you've received an API key, you can develop a map application following the instructions in this documentation.

The Google Maps API is now integrated with the Google AJAX API loader, which creates a common framework for loading and using multiple Google AJAX APIs. For more information, consult the information noted below:

New! Google Mapplets - Build mini-applications to embed on the Google Maps site.

Table of Contents

Audience

This documentation is designed for people familiar with JavaScript programming and object-oriented programming concepts. You should also be familiar with Google Maps from a user's point of view. There are many JavaScript tutorials available on the Web.

This conceptual documentation is not complete and exhaustive; it is designed to let you quickly start exploring and developing cool applications with the Google Maps API. We also publish the Google Maps API Reference which should be relatively complete.

We've recently reorganized the documentation to add more conceptual information and break out discussions into the following key areas:

We hope you find the redesign easier to follow, especially for developers who are new to the Maps API. Feedback on the documentation is welcome as well. Make sure to join the Maps API developer forum to give feedback and discuss the API.

Creating Google Mapplets

The Google Maps API now adds supports for Mapplets (Maps + Gadgets), which allow you to embed externally hosted applications within Google Maps. These mapplets are run within their own iFrames, allowing you to create "mashups of mashups" and mix code from one site with another for example. This opens up a whole new world of coding within Google Maps! Writing Mapplets is easy, though some things are done differently than in the standard Google Maps API. Check out the Google Maps Mapplets documentation and reference for more information.

Using the Google AJAX API Loader

The Google Maps API is now fully integrated with the Google AJAX APIs. This framework allows you to load one API key for all supported Google AJAX APIs (including Google Maps) and also provides a common namespace for each API, allowing different Google APIs to operate together. Don't worry: if you decide not to use the Google AJAX API framework, you can continue to use the existing namespace.

Using the Google AJAX API framework is relatively simple. Changing your application to use the framework involves the following steps:

  • Instead of loading the API from http://maps.google.com/apis, you load the common loader from http://www.google.com/jsapi. You can pass your existing Google Maps API key to this URL:
    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABCDEFG"></script>
  • Load the specific API you want using the google.load method. The google.load method takes an argument for the specific API and version number to load:
    <script type="text/javascript">
    google
    .load("maps", "2");
    </script>
  • Use the google.maps.* namespace for all classes, methods and properties you currently use in the Google Maps API, replacing the G prefix with this namespace. Perform any initialization to your objects using google.setOnLoadCallback(). For example, the GMap2 object is mapped to google.maps.Map2 when using the Google AJAX API loader:
    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABCDEFG"></script>
    <script type="text/javascript">
    google
    .load("maps", "2.x");

    // Call this function when the page has been loaded
    function initialize() {
    var map = new google.maps.Map2(document.getElementById("map"));
    map
    .setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
    }
    google
    .setOnLoadCallback(initialize);
    </script>

Full documentation for using the Google AJAX API loader is available at http://code.google.com/apis/ajax/documentation/.

Programming Notes

Before you start delving into the Google Maps API, you should take note of the following concerns to ensure your application works smoothly across its intended platforms.

Browser Compatibility

The Google Maps API supports the same browsers as the Google Maps website. The script http://maps.google.com/maps?file=api&v=2 can be parsed in almost every browser without errors, so you can safely include that script before checking for compatibility.

Different applications sometimes require different behaviors for users with incompatible browsers. The Maps API provides a global method (GBrowserIsCompatible()) to check compatibility, but it does not have any automatic behavior when it detects an incompatible browser. Most of the examples in this document do not check for browser compatibility, nor do they display an error message for older browsers. Clearly real applications should do something more friendly with incompatible browsers, but we have omitted such checks to make the examples more readable.

Non-trivial applications will inevitably encounter inconsistencies between browsers and platforms. There is no simple solution to these problems, but the Google Maps API developer forum and quirksmode.org are both good resources to find workarounds.

XHTML and VML

We recommend that you use standards-compliant XHTML on pages that contain maps. When browsers see the XHTML DOCTYPE at the top of the page, they render the page in "standards compliance mode," which makes layout and behaviors much more predictable across browsers. Pages without that definition may render in "quirks mode" which can lead to inconsistent layout.

If you want to show polylines on your map (like the lines used by Google Maps to show driving directions), you need to include the VML namespace in your XHTML document to make everything work properly in Internet Explorer. The beginning of your XHTML document should look like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

API Updates

The v parameter within the http://maps.google.com/maps?file=api&v=2 URL refers to the version number of the Google Maps API to use. Most users of the API will want to use the current "Version 2" API by passing the v=2 parameter within that URL. You may instead obtain the latest release (including the latest features) by passing v=2.x instead. However, be aware that the latest release may not be as reliable as the v=2 release. We update the Google Maps API often (sometimes every week), at which point features within the v=2.x release are migrated into the v=2 release unless problems are discovered.

In addition, you may use a "stable" version of the API by passing the v=2.s parameter. This version is updated less often, about every few months. Since the v=2 and v=2.x releases are updated about every two weeks, some developers will prefer to use the stable v=2.s. Please note that the stable version may be several versions behind the current version and therefore may not include some of the latest features.

Each version of the API is labeled as we update it (for example, "Version 2.76"). As we update the API, older code based on previous versions may occasionally not work as advertised. If you absolutely need to peg your application to a particular release of the API, you can do so by explicitly including that version within the v parameter (e.g. v=2.75). However, this is not recommended. It is always best to base your products on the code as it gets updated.

When we do a significant update to the API in the future, we will change up the major version number and post a notice on Google Code and the Maps API developer forum. When that happens we expect to support both versions for at least a month in order to allow you to migrate your code.

The Maps team also transparently updates the API with the most recent bug fixes and performance enhancements. These bug fixes should only improve performance and fix bugs, but we may inadvertently break some API clients. Please use the Maps API developer forum to report such issues.

Upgrading Your v1 Application

This documentation refers to Version 2 of the Maps API, launched on April 3, 2006. If your API uses Version 1 of the Maps API (i.e., you developed your site before April 3, 2006), you should attempt to upgrade your web site. Please see the Version 2 Upgrade Guide for more information.

Examples in the Maps API

Note that most of the examples in this documentation show only relevant JavaScript code, not the full HTML file. You can plug the JavaScript code into your own skeleton HTML file, or you can download the full HTML file for each example by clicking the link after the example.

Reducing Browser Memory Leaks

The Google Maps API encourages the use of function closures, and the API event handling system GEvent attaches events to DOM nodes in such a way that almost inevitably causes some browsers to leak memory, particularly Internet Explorer. Version 2 of the Maps API introduces a new method, GUnload(), that will remove most of the circular references that cause these leaks. You should call GUnload() in the onunload event of your page to reduce the potential that your application leaks memory:

<body onunload="GUnload()">

Using this function has virtually eliminated Internet Explorer memory leaks in Google Maps, though you should test for memory leaks on your own site using tools like Drip if you are noticing memory consumption problems.

Other resources

Here are some additional resources. Note that these sites are not owned or supported by Google.

Troubleshooting

If your code doesn't seem to be working, here are some approaches that might help you solve your problems:

  • Make sure your API key is valid.
  • Look for typos. Remember that JavaScript is a case-sensitive language.
  • Use a JavaScript debugger. In Firefox, you can use the JavaScript console, the Venkman Debugger, or the Firebug add-on. In IE, you can use the Microsoft Script Debugger.
  • Search the Maps API developer forum. If you can't find a post that answers your question, post your question to the group along with a link to a web page that demonstrates the problem.
  • See Other Resources for third party developer resources.


更多请关注http://www.google.com/apis/maps/documentation/#API_Updates
分享到:
评论

相关推荐

    C/C++11-20的标准API中文帮助文档CHM

    C/C++11-20的标准API中文帮助文档CHM是一个非常宝贵的资源,它为C++和C语言的开发者提供了全面、详细的API参考,尤其是在没有官方标准文档的情况下。这个CHM(Compiled Help Manual)文件是一种Windows平台上的离线...

    2019 c++最新中文API文档

    这份"2019 C++最新中文API文档"是为开发者提供的一份宝贵的参考资料,旨在帮助他们更好地理解和使用C++的标准库及API接口。 C++ API(Application Programming Interface)是C++标准库的一部分,它包含了一系列预先...

    Oracle 10g 中文API Oracle Concepts (10g R2) 中文版_V11

    Oracle 10g API 和《Oracle Concepts (10g R2) 中文版_V11》是关于Oracle数据库系统的重要参考资料,尤其对于那些需要深入理解Oracle数据库架构、管理和开发的IT专业人士来说,它是不可或缺的学习资源。 Oracle 10g...

    JavaEE.6.Tutorial(Basic Concepts+完整版)+JavaEE.6.API(chm)

    JavaEE(Java Platform, Enterprise Edition)是Oracle公司提供的一个用于构建企业级Web应用程序的平台,它基于Java技术,为开发人员...而对于已经在JavaEE领域有一定经验的开发者,API文档将是一个宝贵的参考资料。

    谷歌的安卓开发官方演示文档

    安卓开发谷歌文档ppt。由Google Developers Training团队推出的Advanced Android Development终于发布了(当然是英文的)。 这套课程可以作为大学教师的教授内容,也适合已经有 Java 和 Android 相关编程经验的...

    ACIS帮助文档

    ACIS(Advancing Concepts for Interactive Solid Modeling)是一种强大的三维几何建模内核,广泛应用于CAD(计算机辅助设计)、CAE(计算机辅助工程)和CAM(计算机辅助制造)等领域。ACIS为软件开发者提供了一个...

    oracle官方文档-Oracle Database Concepts

    《Oracle Database Concepts》是Oracle公司发布的官方文档,它详尽地介绍了Oracle数据库的核心概念、架构以及操作原理。这篇文档对于想要深入理解Oracle数据库的人来说,无疑是一份宝贵的资源。以下将根据文档内容,...

    Oracle 10g Concepts (Oracle 10g 概念中文手册)——破解版!!

    - Oracle网格架构(Grid Architecture)是Oracle 10g的核心概念之一,旨在提供一种灵活且可扩展的基础设施来支持大型分布式计算环境。它将多个数据库实例组织成一个统一的资源池,通过资源共享提高整体系统的可用性...

    Oracle concepts 第7章翻译 之一 收藏

    Oracle数据库是业界广泛使用的关系型数据库管理系统之一,其内部架构和内存管理机制对于确保数据处理效率至关重要。本章节将详细介绍Oracle实例中的内存组件,包括系统全局区(System Global Area, SGA)和程序全局区...

    elasticsearch2.x离线api

    Elasticsearch是一款广泛使用的开源搜索引擎,基于Lucene构建,以其近实时的搜索能力、水平可扩展性以及丰富的文档处理能力著称。Elasticsearch 2.x系列是这一产品的中早期版本,它提供了一系列的API以供开发者使用...

    Oracle Concepts Oracle概念(10g R2)(中英文对照文档)

    Oracle Concepts是Oracle数据库的核心理论与实践指南,涵盖了Oracle 10g Release 2 (10g R2)的诸多重要概念。这份文档是学习和理解Oracle数据库架构、操作及管理的关键资源,尤其对于DBA(数据库管理员)和开发人员...

    TEE_Client_API_Specification-V1.0_c.pdf

    3. 术语和定义(TERMINOLOGYANDDEFINITIONS):在文档的这一部分中,明确了一些与TEE相关的专业术语,帮助读者更好地理解和后续内容。 4. 缩略语和符号(ABBREVIATIONSANDNOTATIONS):列出了文档中所使用的缩写和...

    IBM仓储管理指导文档(WMS_Concepts_Guide)

    IBM仓储管理指导文档(WMS_Concepts_Guide)是一份针对电子商务仓储管理的学习资料,重点介绍IBM® Sterling 仓储管理系统(WMS)的各个功能和特点。该文档面向所有使用IBM Sterling Warehouse Management System的...

    Oracle 11g Concepts中英文对照.pdf

    Oracle 数据库文档路线图是指 Oracle 数据库的文档结构,提供了一个强大的平台,用于了解和学习 Oracle 数据库。 表和表簇 表和表簇是 Oracle 数据库中的基本结构,包括表、索引、表簇等。表和表簇是 Oracle 数据库...

    oracle官方文档:Oracle Database Concepts 11g Release 2 (11.2)

    ### Oracle Database Concepts 11g Release 2 (11.2):关键知识点解析 #### 一、概述 Oracle Database 11g Release 2(版本号为11.2)是Oracle公司推出的数据库管理系统的一个重要版本。此版本在原有Oracle 11g的...

    C++API手册

    C++ API手册是C++程序员的重要参考资料,它涵盖了C++编程语言的标准库和核心语言特性。这份手册详细解析了从C++98到C++20的各个版本更新,为开发者提供了全面且权威的指导。在C++的发展历程中,每个新版本都引入了...

    ASP.NET.Web.API.2.Beginner.Guide

    This short Book explains Web API design, concepts, features, and help page generation. This is a starter guide for those who want to quickly understand the basics of Web API. Topics covered in this ...

    erd.concepts.v5.0.0.0

    标题“erd.concepts.v5.0.0.0”似乎是指一个关于实体关系图(Entity Relationship Diagram, ERD)的概念版本5.0.0.0的更新或软件包。ERD是一种在数据库设计中广泛使用的工具,用于可视化数据实体、它们之间的关系...

    concepts

    根据给定文件的信息,我们可以提炼出关于Oracle数据库概念的关键知识点。 ### 1. Oracle数据库概述 Oracle数据库是一款由...对于企业和组织而言,Oracle数据库是构建高性能、安全可靠的应用系统的理想选择之一。

    oracle concepts

    Oracle数据库是全球广泛使用的大型关系型数据库管理系统之一,尤其在企业级应用中占据重要地位。《Oracle Concepts》是理解Oracle数据库基础和特性的关键文档,适合初学者和有志于成为Oracle DBA(数据库管理员)的...

Global site tag (gtag.js) - Google Analytics