Vikash Yadav

Hobart & William Smith Colleges

Notebook

12/10/07

Using Google Maps API

So in a moment of downtime, I started experimenting with creating a set of maps that would be integrated with my course on South Asian politics (... sadly, I relax by writing code...).

My first plan (just like all of my grand schemes) was to create my own flash maps using Flash + XML. I went to ammap.com which has a free downloadable map and some documentation to walk you through the editing process. I created my first flash map and played around with the color schemes, zoom levels, etc. using the recommended (free) PSPad XML editor. I thought about adding some basic data, but I quickly realized that this map would simply not be very useful in the long run. I need layers and layers of maps so that students can zoom in an out to find particular cities, provinces, terrain, borders, etc.

So, I decided to table that project and see if I could customize Google maps, which has reasonable coverage in South Asia. As it turns out the process of getting access to Google Maps API is relatively simple. You simply register and they give you an API key which you can then use to develop your own maps by putting the code into your HTML pages. The code is good for all of the pages in a given directory.

The hard part is that you need to know some basic programming language. They do provide a lot of sample code that you can copy (right click and select "view source"), paste into your HTML, and tweak. Since I have limited programming knowledge, this hack/tweak method is my preferred mode of learning. Now, if you're not familiar with JavaScript, you will want to save the first sample code generated by Google when you first get the API key. Keep that file separate from the ones you tweak in case you make a mistake with the code. In fact, you may just want to keep a separate file for all of the successful tweaks.

So here is my first map using Google Maps API code. After plunking the code into my template HTML file (note that some of the JavaScript goes into the "head" tags, I just modified the starting latitude and longitude so that the map is centered on South Asia from the beginning. If you don't know the longitude and latitude that you want to use, you can ask Google (drag the map around, click on the map to get a reading). I also adjusted the map navigation buttons so that they fall over the bottom of the map once the image is double clicked. I think this makes it a bit easier to use the map in a tiny space. Yes, I could make the map bigger, but I am just keeping everything simple for the moment...

My eventual goal is to use the maps to illustrate parts of my lectures, particularly when I have to explain the strategic aspects of the Sino-Indian War and the four Indo-Pak Wars. It is possible to mark up these maps and even create some rather nifty cluster diagrams and other dynamic stuff. For the moment the map will just be useful as a way to encourage students to explore the geography of South Asia. As always, I'll work on that later...

Labels: