[EXTENSION] EGMapKMLFeed

I have created a library that generates KML documents. For further reference on KML please visit http://code.google.com/intl/es/apis/kml/documentation/kmlreference.html.

This extension was developed to work in conjunction with the new release of EGMap (Google Maps Extension) version 2.0. (not compatible with previous releases without proper configuration of afterInit javascript events of the main EGMap class). Nevertheless, you can use it without EGMap library.

The URL of the extension is http://www.yiiframework.com/extension/egmapkmlfeed/

Please use this post for bug reports, suggestions and support.

Thanks

Can’t I generate a feed from an existing EGMap instance? I want to give my user the option to “view current map (with markers) on google earth”, so I could generate the same code, and just render the map as KML instead as javascript.

No you cant, but it is a cool option that I may think to implement for future releases.

Nevertheless, the creation of the KML document is quite easy (example with EGMap Extension)





Yii::import('ext.kml.*');

 

// add one Icon style to the generator

$iconStyle = new EGMapKMLIconStyle('testStyle', 'iconID', 'http://maps.google.com/mapfiles/ms/icons/purple-pushpin.png');

 

$kml->addTag($iconStyle);

 

foreach( $markers as $marker)

{

   $placemark = new EGMapKMLPlacemark('Another Marker');

   $placemark->styleUrl = '#testStyle';


   // if marker has a EGMapInfoWindow you can

  // $placemark->description = $marker->getHtmlInfoWindow->content;

   $placemark->description = 'This marker has <b>HTML</b>';

   // *Note that for KML the lat and lon are the other way around

   // should be lon - lat

   $placemark->addChild(new EGMapKMLPoint($marker->getLng(), $marker->getLat()));

   $kml->addTag($placemark);

}


// generate feed

   $kml->generateFeed();



Antonio,

I am trying to use this extention but I am getting following error.

[font="Verdana"][size="2"]<pre>[/size][/font]

[font="Verdana"][size="2"]Undefined variable: kml[/size][/font]

[font="Verdana"][size="3"][size="3"]C:\home2\arthahit\public_html\arthabusinessgroup\protected\modules\pp\controllers\KlmController.php(43)[/size]

[size="3"][color="#999999"][size="4"]31[/size][/color] * - 2010-10-24: added[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]32[/size][/color] * @param <type> $lat[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]33[/size][/color] * @param <type> $lon[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]34[/size][/color] * @param <type> $miles[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]35[/size][/color] * @param <type> $limit[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]36[/size][/color] * @return boolean[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]37[/size][/color] */[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]38[/size][/color] public function actionGenerate() {[/size][/size][/font]

[font=“Verdana”][size=“3”][size=“3”][color="#999999"][size=“4”]39[/size][/color] Yii::import(‘ext.kml.*’);[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]40[/size][/color] [/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]41[/size][/color] // add Icon styles to the generator[/size][/size][/font]

[font=“Verdana”][size=“3”][size=“3”][color="#999999"][size=“4”]42[/size][/color] $iconStyle = new EGMapKMLIconStyle(‘low-prospectY’, ‘low-prospectY-icon’, ‘http://maps.google.com/mapfiles/ms/micons/blue.png’);[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][size="4"][color="#999999"][size="4"]43[/size][/color] $kml->addTag($iconStyle);[/size][/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]44[/size][/color] [/size][/size][/font]

[font=“Verdana”][size=“3”][size=“3”][color="#999999"][size=“4”]45[/size][/color] $iconStyle = new EGMapKMLIconStyle(‘low-prospectS’, ‘low-prospectS-icon’, ‘http://maps.google.com/mapfiles/ms/micons/blue-dot.png’);[/size][/size][/font]

[font="Verdana"][size="3"][size="3"][color="#999999"][size="4"]46[/size][/color] $kml->addTag($iconStyle)[/size][/size][/font]

[font="Verdana"][size="2"]</pre>[/size][/font]

[font="Verdana"] [/font]

[font="Verdana"][size="2"]


[/size][/font]

[font="Verdana"][size="2"]

 public function actionGenerate() {

        Yii::import('ext.kml.*');

        

        // add Icon styles to the generator

        $iconStyle = new EGMapKMLIconStyle('low-prospectY', 'low-prospectY-icon', 'http://maps.google.com/mapfiles/ms/micons/blue.png');

        $kml->addTag($iconStyle);


        $iconStyle = new EGMapKMLIconStyle('low-prospectS', 'low-prospectS-icon', 'http://maps.google.com/mapfiles/ms/micons/blue-dot.png');

        $kml->addTag($iconStyle);


        $iconStyle = new EGMapKMLIconStyle('med-prospect', 'med-prospect-icon', 'http://maps.google.com/mapfiles/ms/micons/yellow.png');

        $kml->addTag($iconStyle);


        $iconStyle = new EGMapKMLIconStyle('hig-prospect', 'hig-prospect', 'http://maps.google.com/mapfiles/ms/micons/green.png');

        $kml->addTag($iconStyle);


        $iconStyle = new EGMapKMLIconStyle('rej-prospect', 'rej-prospect-icon', 'http://maps.google.com/mapfiles/ms/micons/red.png');

        $kml->addTag($iconStyle);


        $Place1s = Place1::model()->findAll();

        $Place2s = Place2::model()->findAll();


        foreach ($Place1s as $Place1) {

            $Seller = SellerProspectParty::model()->findByPk($Place1->SellerId);

            

            $description = $Seller->AddressLine1 . '<br>' 

                    . $Seller->City . ', ' . $Seller->StateCode . ' - ' . $Seller->PostalCode . '<br>' 

                    . $Seller->Telephone . '<br><br>';


            // create one marker placemark

            $placemark = new EGMapKMLPlacemark($Seller->CompanyName);

            $placemark->styleUrl = '#low-prospectY';

            $placemark->description = $description;

            $placemark->addChild(new EGMapKMLPoint($Place1->Lat, $Place1->Lon,0));

            $kml->addTag($placemark);

        }

        

        $kml->generateFeed();


    }


}[/size][/font]

[font="Verdana"][size="2"]

[/size][/font]

It is working great! All I needed was a line to initiate the class

    &#036;kml = new EGMapKMLFeed;

Glad you found the answer… and apologies for my shortage of time