egmapkmlfeed A KML Feed Generator for Google Maps v3

  1. Requirements
  2. Usage
  3. Resources

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 an international standard maintained by the Open Geospatial Consortium, Inc. (OGC).

The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file. Because the components within a KmlLayer are rendered on demand, the layer allows you to easily manage the rendering of thousands of markers, polylines, and polygons.

Note that you can't access these constituent objects directly, though they each provide click events which return data on those individual objects.

EGMapKMLFeed Generator will allow you to create a KML Feed for your google maps scripts. It was created in order to work in conjunction with the new KML feature of EGMap version 2.0 (Extension also found on this repository).

Handles all supported tags of KML for Google Maps v3 even though includes a set of classes to create your own and also handles the creation of Tags array based so to provide flexibility in your KML docs.

I have created a GitHub repository for those willing to contribute on any of the extensions I created. Please, check the link at the bottom of this wiki.


Developed with Yii 1.1.6.r2877


Unpack the library and place it on your extensions library, then import the library through its correct path.

Example 1

The following example will create a feed to display a marker on the map.


// add one Icon style to the generator
$iconStyle = new EGMapKMLIconStyle('testStyle', 'iconID', '');


// create one marker placemark
$placemark = new EGMapKMLPlacemark('Another Marker');
// tell which style we are going to use
$placemark->styleUrl = '#testStyle';
// the following will be displayed on its bubble info window
$placemark->description = 'This marker has <b>HTML</b>';
// add a tag child EGMapKMLPoint which will tell the
// latitude and longitude of the marker
// *Note that for KML the lat and lon are the other way around
// should be lon - lat
$placemark->addChild(new EGMapKMLPoint('39.718762871171776', '2.903637075424208'));


// generate feed
Example 2

How to create a KML feed that will display a line on the map


// create a line style
$lineStyle = new EGMapKMLLineStyle('lineStyleID', 'lineID', 'FFAA00FF', '4');


// create a Placemark LineString, specifying its info and style
$placemark = new EGMapKMLPlacemark('LineString','Just testing this line', '#lineStyleID');

// create the linestring and give it the coordinates
$line = new EGMapKMLLineString(

// add Child Node to the placemark
$placemark->addChild( $line );

// add Placemark to the Feed Generator

// generate feed
Example 3

Creating a polygon


// create a line style
// colors of Styles are compound like this:
// OPACITY[2]=FF - RED[2]=AA - GREEN[2]=00 - BLUE[2]=FF
// in hexadecimal code
$lineStyle = new EGMapKMLLineStyle('lineStyleID', 'lineID', 'FFAA00FF', '4');


// create the Polygon Placemark
$placemark = new EGMapKMLPlacemark('Polygon','Just testing polygon', '#lineStyleID');

// Add a Polygon Child dynamically.
// Please see how the first coordinate is equal to
// the last coordinate, this is necessary to close 
// the polygon on the map
$placemark->addChild(new EGMapKMLPolygon(true, array('-122.1,37.4,0',
            '-122.0,37.4,0', '-122.0,37.5,0', '-122.1,37.5,0', '-122.1,37.4,0')));


// generate feed


5 0
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Tags: Google, KML, rss, Yii
Developed by: Antonio Ramirez
Created on: Feb 3, 2011
Last updated: 11 years ago


show all

Related Extensions