EGMap 2.0 Google Maps Extension

I have successfully inserted KML support and a child library to create KML feeds.

KML support is on two formats (using geoxml3.js library -required to view KML feeds on localhost) and using KmlLayer of Google Maps.

Also supports another plugin: http://gmaps-samples-v3.googlecode.com/svn/trunk/latlng-to-coord-control/latlng-to-coord-control.html

But I am having an issue to update the library and I need some advice. The new version has been rewritten nearly from scratch and now normally used methods to set properties have been deprecated by the use of a base object with magic setters and getters. For example:




// old versions

$gMap->setOption('zoom',<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />;

// new version

$gMap->zoom = 8;



So, updating the extension on the Yii library (EGMap) will may cause confusion. Should I use my blog instead and a GiHub or google.code project? Or do you think it wont an issue to include this new version and report about the changes.

I am concern about that some users may update to the new version the library and find that is not backwards compatible.

Thanks for your feedback

Hi

This is greate extension :), is there way to fill form (latitude and longitude) by clicking on map?

And i get error with example 3




function hf(a){a=a.g[9];return a!=k?a:...his.b();this.d=b;this.A=c}this.o=a});



and example 4




var marker1 = new MarkerWithLabel({map:egmap_0, 



I use this widget in partial.

Hi micz, thanks for your words. It is strange that they do not work as I tested them before posting. What do you mean you use it in partial, in renderPartial? if that is so, you need to force processOutput in order to correctly register the scripts.

About your question, the extension allows you to do whatever you want with the APi but it does not have that feature implemented by default. What you are asking is what I have created for my own CMS (you can see the picture in this thread in my previous posts -http://www.yiiframework.com/forum/index.php?/topic/14445-egmap-google-maps-extension-now-v18-please-update/page__st__20__p__77442#entry77442) but no, it doesn’t do it by itself.

I doubt this is an issue with the extension but was wondering if anyone else was having this strange problem…

This past week, the map has been placing one of my markers in the wrong location. Instead of being in the middle of the US, it is being placed in the Gulf of Guinea (see images). I haven’t changed the address since I started using the extension. It is always the same marker that is place incorrectly and it happens about 75% of the time.

Anyone else having a problem with incorrectly placed markers?

Thanks!

Hi there Farberama,

Could you please check the latitude and longitude annotations in both cases? It seems that could be the problem.

I have made some research on the points and I don’t see how it could be. I have used http://www.findlatitudeandlongitude.com/ and look for the Belleview, Illinois lat and lon… and the other point is completely displaced.

Can you include the end javascript code in both cases Farberama? Strange

here is the javascript when it works correctly…


<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {

jQuery('#yw0').yiiListView({'ajaxUpdate':['yw0'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'list-view-loading','sorterClass':'sorter'});

});

window.onload=function() {


  			//  Call this function when the page has been loaded

			  function egmap_1_init()

			  {

			    var mapOptions = {center:new google.maps.LatLng(38.6130569, -90.32487375),

zoom:10.,

mapTypeId:google.maps.MapTypeId.ROADMAP};

			    egmap_0 = new google.maps.Map(document.getElementById("egmap_1"), mapOptions);

			    info_window0 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/benzelLogoBig.gif\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $200,000s<br/><a href=\"#1\">More Information</a></div>"});

 

    		var marker0 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.396071, -90.388323)});

    google.maps.event.addListener(marker0, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window0; info_window0.open(egmap_0,marker0);});


      info_window1 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/bradfordLogoBig.gif\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $290,000s<br/><a href=\"#2\">More Information</a></div>"});

 

    		var marker1 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.7715559, -90.6770389)});

    google.maps.event.addListener(marker1, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window1; info_window1.open(egmap_0,marker1);});


      info_window2 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/buderLogoBig.gif\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $160,000s<br/><a href=\"#3\">More Information</a></div>"});

 

    		var marker2 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.623143, -90.23015)});

    google.maps.event.addListener(marker2, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window2; info_window2.open(egmap_0,marker2);});


      info_window3 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/waldenPondLogoBig.png\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $180,000s<br/><a href=\"#4\">More Information</a></div>"});

 

    		var marker3 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.814131, -90.722853)});

    google.maps.event.addListener(marker3, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window3; info_window3.open(egmap_0,marker3);});


      info_window4 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/theodoreridgeLogoBig.gif\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $210,000s<br/><a href=\"#5\">More Information</a></div>"});

 

    		var marker4 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.420086, -90.397212)});

    google.maps.event.addListener(marker4, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window4; info_window4.open(egmap_0,marker4);});


      info_window5 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/westendLogoBig.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $180,000s<br/><a href=\"#10\">More Information</a></div>"});

 

    		var marker5 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.655657, -90.286292)});

    google.maps.event.addListener(marker5, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window5; info_window5.open(egmap_0,marker5);});


      info_window6 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/RichardsonGlenLogoBig.jpg\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $220,000s<br/><a href=\"#12\">More Information</a></div>"});

 

    		var marker6 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.4226143, -90.4002788)});

    google.maps.event.addListener(marker6, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window6; info_window6.open(egmap_0,marker6);});


      info_window7 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/wellstonHeightsLogo.png\" alt=\"\" /><br/>St. Louis County, MO<br/>From the $110,000s<br/><a href=\"#13\">More Information</a></div>"});

 

    		var marker7 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.672282, -90.2896899)});

    google.maps.event.addListener(marker7, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window7; info_window7.open(egmap_0,marker7);});


      info_window8 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/terryParkPlaceLogo.png\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $200,000s<br/><a href=\"#14\">More Information</a></div>"});

 

    		var marker8 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.685446, -90.437446)});

    google.maps.event.addListener(marker8, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window8; info_window8.open(egmap_0,marker8);});


      info_window9 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/CorisandeLogoBig.png\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $220,000s<br/><a href=\"#17\">More Information</a></div>"});

 

    		var marker9 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.4907539, -90.44192)});

    google.maps.event.addListener(marker9, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window9; info_window9.open(egmap_0,marker9);});


      info_window10 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/AP-MH-Logo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $200,000s<br/><a href=\"#15\">More Information</a></div>"});

 

    		var marker10 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.609274, -90.222576)});

    google.maps.event.addListener(marker10, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window10; info_window10.open(egmap_0,marker10);});


      info_window11 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/NewTownlogoWEBcommunities.png\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $260,000s<br/><a href=\"#18\">More Information</a></div>"});

 

    		var marker11 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.8300428, -90.5184231)});

    google.maps.event.addListener(marker11, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window11; info_window11.open(egmap_0,marker11);});


      info_window12 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/terryParkPlaceLogo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $260,000s<br/><a href=\"#22\">More Information</a></div>"});

 

    		var marker12 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.582419, -90.271811)});

    google.maps.event.addListener(marker12, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window12; info_window12.open(egmap_0,marker12);});


      info_window13 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/boulevardHeightsweblogo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $210,000s<br/><a href=\"#19\">More Information</a></div>"});

 

    		var marker13 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.5607579, -90.2711606)});

    google.maps.event.addListener(marker13, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window13; info_window13.open(egmap_0,marker13);});


      info_window14 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/Indian-Springs-Logo.png\" alt=\"\" /><br/>St. Clair County, IL<br/>From the $0s<br/><a href=\"#20\">More Information</a></div>"});

 

    		var marker14 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.5577459, -89.9268945)});

    google.maps.event.addListener(marker14, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window14; info_window14.open(egmap_0,marker14);});


      

			  }

			  egmap_1_init();

			

};

/*]]>*/

</script>



Here is the javascript for when it’s placed incorrectly…


<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {

jQuery('#yw0').yiiListView({'ajaxUpdate':['yw0'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'list-view-loading','sorterClass':'sorter'});

});

window.onload=function() {


  			//  Call this function when the page has been loaded

			  function egmap_1_init()

			  {

			    var mapOptions = {center:new google.maps.LatLng(19.4150214, -45.3614265),

zoom:3.,

mapTypeId:google.maps.MapTypeId.ROADMAP};

			    egmap_0 = new google.maps.Map(document.getElementById("egmap_1"), mapOptions);

			    info_window0 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/benzelLogoBig.gif\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $200,000s<br/><a href=\"#1\">More Information</a></div>"});

 

    		var marker0 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.396071, -90.388323)});

    google.maps.event.addListener(marker0, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window0; info_window0.open(egmap_0,marker0);});


      info_window1 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/bradfordLogoBig.gif\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $290,000s<br/><a href=\"#2\">More Information</a></div>"});

 

    		var marker1 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.7715559, -90.6770389)});

    google.maps.event.addListener(marker1, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window1; info_window1.open(egmap_0,marker1);});


      info_window2 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/buderLogoBig.gif\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $160,000s<br/><a href=\"#3\">More Information</a></div>"});

 

    		var marker2 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.623143, -90.23015)});

    google.maps.event.addListener(marker2, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window2; info_window2.open(egmap_0,marker2);});


      info_window3 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/waldenPondLogoBig.png\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $180,000s<br/><a href=\"#4\">More Information</a></div>"});

 

    		var marker3 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.814131, -90.722853)});

    google.maps.event.addListener(marker3, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window3; info_window3.open(egmap_0,marker3);});


      info_window4 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/theodoreridgeLogoBig.gif\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $210,000s<br/><a href=\"#5\">More Information</a></div>"});

 

    		var marker4 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.420086, -90.397212)});

    google.maps.event.addListener(marker4, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window4; info_window4.open(egmap_0,marker4);});


      info_window5 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/westendLogoBig.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $180,000s<br/><a href=\"#10\">More Information</a></div>"});

 

    		var marker5 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.655657, -90.286292)});

    google.maps.event.addListener(marker5, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window5; info_window5.open(egmap_0,marker5);});


      info_window6 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/RichardsonGlenLogoBig.jpg\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $220,000s<br/><a href=\"#12\">More Information</a></div>"});

 

    		var marker6 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.4226143, -90.4002788)});

    google.maps.event.addListener(marker6, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window6; info_window6.open(egmap_0,marker6);});


      info_window7 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/wellstonHeightsLogo.png\" alt=\"\" /><br/>St. Louis County, MO<br/>From the $110,000s<br/><a href=\"#13\">More Information</a></div>"});

 

    		var marker7 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.672282, -90.2896899)});

    google.maps.event.addListener(marker7, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window7; info_window7.open(egmap_0,marker7);});


      info_window8 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/terryParkPlaceLogo.png\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $200,000s<br/><a href=\"#14\">More Information</a></div>"});

 

    		var marker8 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.685446, -90.437446)});

    google.maps.event.addListener(marker8, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window8; info_window8.open(egmap_0,marker8);});


      info_window9 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/CorisandeLogoBig.png\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $220,000s<br/><a href=\"#17\">More Information</a></div>"});

 

    		var marker9 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.4907539, -90.44192)});

    google.maps.event.addListener(marker9, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window9; info_window9.open(egmap_0,marker9);});


      info_window10 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/AP-MH-Logo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $200,000s<br/><a href=\"#15\">More Information</a></div>"});

 

    		var marker10 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.609274, -90.222576)});

    google.maps.event.addListener(marker10, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window10; info_window10.open(egmap_0,marker10);});


      info_window11 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/NewTownlogoWEBcommunities.png\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $260,000s<br/><a href=\"#18\">More Information</a></div>"});

 

    		var marker11 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.8300428, -90.5184231)});

    google.maps.event.addListener(marker11, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window11; info_window11.open(egmap_0,marker11);});


      info_window12 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/terryParkPlaceLogo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $260,000s<br/><a href=\"#22\">More Information</a></div>"});

 

    		var marker12 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.582419, -90.271811)});

    google.maps.event.addListener(marker12, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window12; info_window12.open(egmap_0,marker12);});


      info_window13 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/boulevardHeightsweblogo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $210,000s<br/><a href=\"#19\">More Information</a></div>"});

 

    		var marker13 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});

    google.maps.event.addListener(marker13, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window13; info_window13.open(egmap_0,marker13);});


      info_window14 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/Indian-Springs-Logo.png\" alt=\"\" /><br/>St. Clair County, IL<br/>From the $0s<br/><a href=\"#20\">More Information</a></div>"});

 

    		var marker14 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});

    google.maps.event.addListener(marker14, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window14; info_window14.open(egmap_0,marker14);});


      

			  }

			  egmap_1_init();

			

};

/*]]>*/

</script>



The marker in question is the last marker (marker14). It seems the LatLng is being set to (0, 0) for some reason. I also noticed that it isn’t being set for marker13 either.

I pull the addresses out of the database with the following code…




<?php

	Yii::import('application.extensions.gmaps.*');


	$gMap = new EGMap();

	 // Not needed but you can do it for more control

	 // over IDs

	 // $gMap->setContainerId('map2');

	 // changing proportions

	 $gMap->setWidth(640);

	 $gMap->setHeight(470);

	 

	foreach($communities as $community)

	{

	

		$popUp = '<div style=\'text-align:center; padding:5px\'>'

			.CHtml::image(Yii::getPathOfAlias('images').CHtml::encode($community->logoURL),'',array('width'=>'150px')).	

		 '<br/>'.$community->location->description.

		 '<br/>From the '.$community->fromPrice().'s'.

		 '<br/>'.CHtml::link("More Information", "#".$community->id, array()).

		 '</div>';

		 // Create GMapInfoWindow

		 $info_window = new EGMapInfoWindow($popUp);

	

		 // Create geocoded address

		 $geocoded_address = new EGMapGeocodedAddress($community->address);

		 $geocoded_address->geocode($gMap->getGMapClient());

		 

		 $marker = new EGMapMarker($geocoded_address->getLat(), $geocoded_address->getLng());

		 $marker->addHtmlInfoWindow($info_window);

	

		 // Add marker on geocoded address

		 $gMap->addMarker($marker);

	}	 

	 $gMap->centerAndZoomOnMarkers();

	 $gMap->renderMap();

?>



Thanks for your help.

Hi Farberama,

Thanks for using the extension. I have seen your code and makes no-sense at all… I mean in terms of what is happening. It gets no latitude and longitude at all, that is why the zero values, so this could be an issue of the reverse geocoding google service as it is happening only with the last marker, not the ones before.




// OK

  var marker14 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.5577459, -89.9268945)});

--------

// NOK

 var marker14 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});



I recommend you to do this, as we cannot rely on the google external service constantly. Include on your Community table two more fields, latitude and longitude. When you do reverse geocoding, and if lat and lon are not zero valued, save them to the database for future requests (that will speed up your application too). Try a certain number of times the same requests (1 or 2 that depends on you) until you get a google response, if still zero valued, do not show marker until following request.

The following is an example code, just for you to think about it, it is not a working example.





if($community->latitude == 0 && $community->longitude == 0) {


       // Create geocoded address (maybe a recursive function? you can do while until loop too... 

       $geocoded_address = new EGMapGeocodedAddress($community->address);

       $geocoded_address->geocode($gMap->getGMapClient());


       if( $geocoded_address->getLat() != 0 && $geocoded_address->getLng() != 0)

       {

               $community->latitude = $geocoded_address->getLat();

               $community->longitude = $geocoded_address->getLng();

               $community->Save();

       }else // do it again until getLat() != 0 && getLng() != 0 or counter maximum times reached certain number


} else // add marker

...

...

 $marker = new EGMapMarker($geocoded_address->getLat(), $geocoded_address->getLng());

 $marker->addHtmlInfoWindow($info_window);

 // Add marker on geocoded address

 $gMap->addMarker($marker);



I just looked at javascript again and this time the last 5 markers’ LatLng is being set to (0, 0). This is so strange because it doesn’t happen every time.


<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {

jQuery('#yw0').yiiListView({'ajaxUpdate':['yw0'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'list-view-loading','sorterClass':'sorter'});

});

window.onload=function() {


  			//  Call this function when the page has been loaded

			  function egmap_1_init()

			  {

			    var mapOptions = {center:new google.maps.LatLng(19.4070655, -45.3614265),

zoom:3.,

mapTypeId:google.maps.MapTypeId.ROADMAP};

			    egmap_0 = new google.maps.Map(document.getElementById("egmap_1"), mapOptions);

			    info_window0 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/benzelLogoBig.gif\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $200,000s<br/><a href=\"#1\">More Information</a></div>"});

 

    		var marker0 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.396071, -90.388323)});

    google.maps.event.addListener(marker0, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window0; info_window0.open(egmap_0,marker0);});


      info_window1 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/bradfordLogoBig.gif\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $290,000s<br/><a href=\"#2\">More Information</a></div>"});

 

    		var marker1 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.7715559, -90.6770389)});

    google.maps.event.addListener(marker1, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window1; info_window1.open(egmap_0,marker1);});


      info_window2 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/buderLogoBig.gif\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $160,000s<br/><a href=\"#3\">More Information</a></div>"});

 

    		var marker2 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.623143, -90.23015)});

    google.maps.event.addListener(marker2, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window2; info_window2.open(egmap_0,marker2);});


      info_window3 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/waldenPondLogoBig.png\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $180,000s<br/><a href=\"#4\">More Information</a></div>"});

 

    		var marker3 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.814131, -90.722853)});

    google.maps.event.addListener(marker3, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window3; info_window3.open(egmap_0,marker3);});


      info_window4 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/theodoreridgeLogoBig.gif\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $210,000s<br/><a href=\"#5\">More Information</a></div>"});

 

    		var marker4 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.420086, -90.397212)});

    google.maps.event.addListener(marker4, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window4; info_window4.open(egmap_0,marker4);});


      info_window5 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/westendLogoBig.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $180,000s<br/><a href=\"#10\">More Information</a></div>"});

 

    		var marker5 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.655657, -90.286292)});

    google.maps.event.addListener(marker5, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window5; info_window5.open(egmap_0,marker5);});


      info_window6 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/RichardsonGlenLogoBig.jpg\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $220,000s<br/><a href=\"#12\">More Information</a></div>"});

 

    		var marker6 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.4226143, -90.4002788)});

    google.maps.event.addListener(marker6, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window6; info_window6.open(egmap_0,marker6);});


      info_window7 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/wellstonHeightsLogo.png\" alt=\"\" /><br/>St. Louis County, MO<br/>From the $110,000s<br/><a href=\"#13\">More Information</a></div>"});

 

    		var marker7 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.672282, -90.2896899)});

    google.maps.event.addListener(marker7, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window7; info_window7.open(egmap_0,marker7);});


      info_window8 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/terryParkPlaceLogo.png\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $200,000s<br/><a href=\"#14\">More Information</a></div>"});

 

    		var marker8 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.685446, -90.437446)});

    google.maps.event.addListener(marker8, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window8; info_window8.open(egmap_0,marker8);});


      info_window9 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/CorisandeLogoBig.png\" alt=\"\" /><br/>Jefferson County, MO<br/>From the $220,000s<br/><a href=\"#17\">More Information</a></div>"});

 

    		var marker9 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(38.4907539, -90.44192)});

    google.maps.event.addListener(marker9, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window9; info_window9.open(egmap_0,marker9);});


      info_window10 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/AP-MH-Logo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $200,000s<br/><a href=\"#15\">More Information</a></div>"});

 

    		var marker10 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});

    google.maps.event.addListener(marker10, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window10; info_window10.open(egmap_0,marker10);});


      info_window11 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/NewTownlogoWEBcommunities.png\" alt=\"\" /><br/>St. Charles County, MO<br/>From the $260,000s<br/><a href=\"#18\">More Information</a></div>"});

 

    		var marker11 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});

    google.maps.event.addListener(marker11, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window11; info_window11.open(egmap_0,marker11);});


      info_window12 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/terryParkPlaceLogo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $260,000s<br/><a href=\"#22\">More Information</a></div>"});

 

    		var marker12 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});

    google.maps.event.addListener(marker12, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window12; info_window12.open(egmap_0,marker12);});


      info_window13 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/boulevardHeightsweblogo.png\" alt=\"\" /><br/>St. Louis City, MO<br/>From the $210,000s<br/><a href=\"#19\">More Information</a></div>"});

 

    		var marker13 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});

    google.maps.event.addListener(marker13, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window13; info_window13.open(egmap_0,marker13);});


      info_window14 = new google.maps.InfoWindow({content:"<div style=\'text-align:center; padding:5px\'><img width=\"150px\" src=\"/BuilderApp/public_html/images/Indian-Springs-Logo.png\" alt=\"\" /><br/>St. Clair County, IL<br/>From the $0s<br/><a href=\"#20\">More Information</a></div>"});

 

    		var marker14 = new google.maps.Marker({map:egmap_0,

position:new google.maps.LatLng(0, 0)});

    google.maps.event.addListener(marker14, "click", function() {if (egmap_0_info_window) egmap_0_info_window.close(); egmap_0_info_window = info_window14; info_window14.open(egmap_0,marker14);});


      

			  }

			  egmap_1_init();

			

};

/*]]>*/

</script>



Thanks Antonio! I’ll try this.

Remember than the code is an example, I would elaborate a better approach for your coding…

That did the trick. Thanks Antonio!

Here is what I did…


 if($community->latitude == 0 || $community->longitude == 0) 

 {

	// Create geocoded address

	$geocoded_address = new EGMapGeocodedAddress($community->address);

	$geocoded_address->geocode($gMap->getGMapClient());

	 

	while($geocoded_address->getLat() == 0 || $geocoded_address->getLng() == 0)

	{

		$geocoded_address->geocode($gMap->getGMapClient());

	}

	

	$community->latitude = $geocoded_address->getLat();

	$community->longitude = $geocoded_address->getLng();

	$community->Save();

 }


$marker = new EGMapMarker($community->latitude, $community->longitude);



Because it’s possible (though not likely) that the while loop could result in an infinite loop if zeros continue to be returned for the longitude and latitude, I might change the while loop to a for loop to limit the number of possible loops. But, so far I haven’t run into this problem.

Thanks again for your help!

No need to thank me, I am glad it worked. But, I highly recommend you to set a number of loops and if still fails, do a ‘continue’ to jump onto the next on the loop.

The way you set this up is that the reverse geocoding is only requested once per community, next calls it will be rendered from your very own database. Great isnt it?

Best

Is there an easy way to generate a KML for opening the current map and markers in Google Earth? All the data is in hand, shouldn’t be too hard to generate it.

This is the "KML" support planned for v2.0?

I have already uploaded the library EGMapKMLFeed KML Generator library (check extensions for EGMapKMLFeed). The version 2.0 is on the way and will include that library too.

Please check the already uploaded version. EGMap 2.0

Cheers

I’ve got one small bug, that was in previous version too, I use Apache with Windows for development, and url paths that contain the ‘\’ character doesn’t seem to work, like the paths generated by the “registerPlugins” function. Changing DIRECTORY_SEPARATOR to ‘/’ on the urls seems to fix it (and to me this should be the correct url generated).




  	private function registerPlugins(){

...

				foreach($p['js'] as $js)

					$cs->registerScriptFile($assetUrl.'/'.$js,CClientScript::POS_END);

...

        }



"/" is for URLs, DIRECTORY_SEPARATOR for directory paths.

Thank you very much for this… I will update the extension asap…

Edit: Update is done…

Hello Antonio!

Do you plan to implement that in future versions?

Kind regards.

Hey Bandini,

I can build an example that does exactly that if you want me to. The library allow us to build it.

The idea behind the library is to allow us to create whatever we want, to provide us flexibility, so I do not think that implementing a pure CMS feature could be of any help for you.

Tell me if you want me to write an article about that and I will. Is easier than you think ;)

Sure. I’ve been reading the souces trying to figure how to do that, but I’ m new to yii and I’m a little lost.

Thanks for your kind offer!