Sunday, April 3, 2011

Using Google Earth API and KML for your business

Although its almost 6 yrs since when Google launched its Google Map API, and I built my first app around it for entrip.com, it has been evolving lot and lots of possibilities have been created.
A new application is result of new business requirement or introduction of new technology which can be used for solving old business problems.
Next step of Google Map api is now Google earth API, as processing power and bandwidth is going cheaper its becoming more feasible and attactive to build apps around google earth. A browser plugin makes google earth api more killing and pervasive.
The Google Earth Plug-in and its JavaScript API let you embed Google Earth, a true 3D digital globe, into your web pages. Using the API you can draw markers and lines, drape images over the terrain, add 3D models, or load KML files, allowing you to build sophisticated 3D map applications. The Google Earth API is a free service, available for any web site that is free to consumers.
Google Earth provides the following functionalities that adds to the advantage of using it:

a. Google Street View
b. Google Aerial View
c. Google 3D buildings
and many more...

The main new and interesting thing google introduces is KML ( Key Hole Markup Language ).
KML is a file format used to display geographic data in an Earth browser, such as Google Earth, Google Maps, and Google Maps for mobile. You can create KML files to pinpoint locations, add image overlays, and expose rich data in new ways. KML is used for the following reasons:

a. Casual users
Description: Placemark homes, plan and document journeys.
b. Scientists
Description: See detailed mappings of natural resources and trends.
c. Non-Profits
Description: Highlight problems and advocate change
d. Students and Educators
Description: Explore historic and current places, people and events.

Using Above technologies just created a simple app which is just combination of
Goggle Earth API + KML Data + PHP + MYSQL + AJAX

Steps done taken are

1) Develope KML to locate particular co-ordinate and mark it using graphical shapes such are ring, polygon

2) Initialise the Google earth API

google.earth.createInstance('map3d', initCB, failureCB);

3) In-order to send the request to the PHP script Ajax has been implemented.

function addcityajax()
{
var data = "load=citydropdown";

$.ajax({
url: "get_kml_data.php",
type: 'GET',
data: data,
success: function(data){
//code to process kml data response
}
});
}



Some useful links
Using PHP and Mysql to generate KML
test your KML online tool