Tuesday, April 1, 2008

Google Maps API Basics

Introduction


Google Maps API (Application Programming Interface) lets you embed Google maps in web pages. It uses Java Script for scripting. In order to use the Maps API you need a API key that can be obtained by signing up with Google for Maps API. After obtaining the API key you can develop map applications.


Loading the Google Maps API

Google Maps API is loaded with the help of Java Script code in script tag. Basically you make the src attribute of script tag to point to http://maps.google.com/maps?file=api&v=2&key=abcdefg

This URL points to the location of the JavaScript file that includes all of the symbols and definitions you need for using the Google Maps API. Your page must contain a script tag pointing to this URL, using the key you received when you signed up for the API. In this example the key is shown as "abcdefg."

Localization of Google Maps API

Maps API also introduces the concept of Mapplets (a combination of maps and gadgets). Mapplets allow you to embed external applications into Google Maps. It also includes support for localization. It uses English by default but one can change hl attribute in script tag of Java Script to change this default behavior to support the language of your choice.

For example, to display a Maps API application in German, add &hl=de to the tag as shown below:

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

No comments: