CGGoogleMaps address to GLatLng [SOLVED]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

CGGoogleMaps address to GLatLng [SOLVED]

Post by antosha »

Hi,
I want to draw a polyline from two dynamicaly loaded (with {cggm_add_dynpoint} plugin).
However, google API requires Lat/Long coordinates to draw a line, I need to find a way to automatically retrieve coordinates from address.

Code: Select all

<__script__ type="text/javascript">

var polyOptions = {geodesic:true};
var polyline = new GPolyline([
  new GLatLng(I NEED TO FIND THESE COORDINATES GENERATED FROM ADDRESS),
  new GLatLng(I NEED TO FIND THESE COORDINATES GENERATED FROM ADDRESS)
  ], "#f36c25", 5, 0.8, polyOptions);
map.addOverlay(polyline);
  if (GBrowserIsCompatible()) {
        map.addOverlay(polyline);
  }
</__script>
Thanks
Last edited by antosha on Sat Jun 12, 2010 9:44 pm, edited 1 time in total.
Follow me on twitter: end_tone
Linked In: levchenkoanton
janb

Re: CGGoogleMaps address to GLatLng

Post by janb »

Hi

Have you looked at the CGGM GetCoordsFromAddress() function?


JanB
janb

Re: CGGoogleMaps address to GLatLng

Post by janb »

Example:

UDT named 'cggm_getaddr' :

Code: Select all


global $gCms;
$cggm =& $gCms->modules['CGGoogleMaps']['object'];

$addr1 = 'SomeAddress 1';
$addr2 = 'SomeAddress 2';

$smarty->assign('point1',implode(',',$cggm->GetCoordsFromAddress($addr1)) );
$smarty->assign('point2',implode(',',$cggm->GetCoordsFromAddress($addr2)) );


Add to the top and to the bottom of the CGGoogleMaps template:

Code: Select all


{cggm_getaddr}
..
..
..
..
..
<__script__ type="text/javascript">
{literal}
//    map.setCenter(new GLatLng({/literal}{$MyGeoLocationLatLon}{literal}));

var polyOptions = {geodesic:true};
var polyline = new GPolyline([
  new GLatLng({/literal}{$point1}{literal}),
  new GLatLng({/literal}{$point2}{literal})
  ], "#f36c25", 5, 0.8, polyOptions);
map.addOverlay(polyline);
  if (GBrowserIsCompatible()) {
        map.addOverlay(polyline);
  }
{/literal}
</__script>
JanB
Last edited by janb on Tue Jun 08, 2010 8:55 am, edited 1 time in total.
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Re: CGGoogleMaps address to GLatLng

Post by antosha »

Hi,
Thanks a lot for your reply!
However, for some reason I can't get it working.
As you told me, I created the new UDT, modified the CGGoogleMaps template and added {CGGoogleMaps} into my content page.

Now the content box where the google map is suppose to appear is blank.
Follow me on twitter: end_tone
Linked In: levchenkoanton
janb

Re: CGGoogleMaps address to GLatLng

Post by janb »

Hi

Maybe a dumb question, but did you leave the original template code untouched ?
..and added {cggm_getaddr} to the top and the java-script section to the bottom (have to be after {$google_map_js})?

JanB
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Re: CGGoogleMaps address to GLatLng

Post by antosha »

Well, your question wasn't that dumb, since the reason why the page was showing blank was because I defined
{cggm_poadd_dynint} tags after {CGGoogleMaps} one (it needs to be before)  :P

However now I am facing another problem, which is passing the two addresses from the two {content block} into the UDT.

What I did :

In my CMS template :

Code: Select all

{capture name=pointc1 assign=addresspoint1}
  {content block='point 1' oneline='true'}
{/capture}
{capture name=pointc2 assign=addresspoint2}
  {content block='point 2' oneline='true'}
{/capture}
{cggm_poadd_dynint map="1" name='aaa' address=$addresspoint1} {cggm_add_dynpoint map="1" name='asda' address=$addresspoint2}
{content}
CGGoogleMaps template :

Code: Select all

...
{$google_map_js}
{cggm_getaddr}

<__script__ type="text/javascript">
{literal}
//    map.setCenter(new GLatLng({/literal}{$MyGeoLocationLatLon}{literal}));

var polyOptions = {geodesic:true};
var polyline = new GPolyline([
  new GLatLng({/literal}{$point1}{literal}),
  new GLatLng({/literal}{$point2}{literal})
  ], "#f36c25", 5, 0.8, polyOptions);
map.addOverlay(polyline);
  if (GBrowserIsCompatible()) {
        map.addOverlay(polyline);
  }
{/literal}
</__script>
<!-- end display map -->
UDT:

Code: Select all

global $gCms;
$cggm =& $gCms->modules['CGGoogleMaps']['object'];

$smarty->assign('point1',implode(',',$cggm->GetCoordsFromAddress($addresspoint1)) );
$smarty->assign('point2',implode(',',$cggm->GetCoordsFromAddress($addresspoint2)) );

Now what happens, the google map shows the two points, but doesn't show the polyline and displays the following error after the Map :
Warning: implode() [function.implode]: Invalid arguments passed in  /XXXX/XX/XXXX/XXXX//lib/content.functions.php(771) : eval()'d code on line 4

Warning: implode() [function.implode]: Invalid arguments passed in /XXXX/XX/XXXX/XXXX/content.functions.php(771) : eval()'d code on line 5
If I replace GetCoordsFromAddress($addresspoint1)) ); to GetCoordsFromAddress(New York City, USA)) ); for example, the line will draw correctly.

So if I understand right, the $addresspoint1 and $addresspoint2 are for some reason not passed to the UDT...
Last edited by antosha on Thu Jun 10, 2010 6:33 am, edited 1 time in total.
Follow me on twitter: end_tone
Linked In: levchenkoanton
janb

Re: CGGoogleMaps address to GLatLng

Post by janb »

Hi

You have a typo in your template..

Code: Select all

{cggm_poadd_dynint map="1" name='aaa' address=$addresspoint1} {cggm_add_dynpoint map="1" name='asda' address=$addresspoint2}
should be

Code: Select all

{cggm_add_dynpoint map="1" name='aaa' address=$addresspoint1} {cggm_add_dynpoint map="1" name='asda' address=$addresspoint2}
I have not tested this the way you describe, but will do as soon i have time to..

JanB
janb

Re: CGGoogleMaps address to GLatLng

Post by janb »

Hi

Maybe this could be better:
Shortened the parameter names a little bit..

In your template:

Code: Select all


{capture name=pointc1 assign=addr1}
  {content block='point 1' oneline='true'}
{/capture}
{capture name=pointc2 assign=addr2}
  {content block='point 2' oneline='true'}
{/capture}

{cggm_getaddr addr1="$addr1|Point 1" addr2="$addr2|Point 2" map="1"}
{content}

UDT cggm_getaddr

Code: Select all


global $gCms;
$cggm =& $gCms->modules['CGGoogleMaps']['object'];

$map = $params['map'];
$param1 = explode('|',$params['addr1']);
$param2 = explode('|',$params['addr2']);

$cggm->AddDynamicPoint($map,$param1[1],'',$param1[0]);
$cggm->AddDynamicPoint($map,$param2[1],'',$param2[0]);

$smarty->assign('point1',implode(',',$cggm->GetCoordsFromAddress($param1[0])) );
$smarty->assign('point2',implode(',',$cggm->GetCoordsFromAddress($param2[0])) );

CGGoogleMaps template :
(remove the UDT. ...and the map.setCenter line. That's a ref to a GeoLocation tag i use)

Code: Select all


{$google_map_js}

<__script__ type="text/javascript">
{literal}

var polyOptions = {geodesic:true};
var polyline = new GPolyline([
  new GLatLng({/literal}{$point1}{literal}),
  new GLatLng({/literal}{$point2}{literal})
  ], "#f36c25", 5, 0.8, polyOptions);
map.addOverlay(polyline);
  if (GBrowserIsCompatible()) {
        map.addOverlay(polyline);
  }
{/literal}
</__script>
<!-- end display map -->

..and in your content page just the {CGGoogleMaps} tag.

You can of course put the UDT in the content page before the CGGoogleMaps tag but then you have to remove it from the template. In that way it's more dynamic and you can have several pages with different maps, points and lines.

JanB
Last edited by janb on Thu Jun 10, 2010 9:35 am, edited 1 time in total.
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Re: CGGoogleMaps address to GLatLng

Post by antosha »

Thank you so much, it works great now !
Two more things: in your code, where can I define the point icon and how can I change the point name to be the same as its address?
Follow me on twitter: end_tone
Linked In: levchenkoanton
janb

Re: CGGoogleMaps address to GLatLng

Post by janb »

Hi

Since we do not need to define the address twice, we can use the icon instead as the second value in the addrx parameter.
The icon name have to be defined in CGGoogleMaps.

Change the tag to:

Code: Select all

{cggm_getaddr addr1="$addr1|building" addr2="$addr2|building" map="1"}
where building is the icon name

Change UDT cggm_getaddr to:

Code: Select all

global $gCms;
$cggm =& $gCms->modules['CGGoogleMaps']['object'];

$map = $params['map'];
$param1 = explode('|',$params['addr1']);
$param2 = explode('|',$params['addr2']);

$cggm->AddDynamicPoint($map,trim($param1[0]),'',$param1[0],'','',$param1[1]);
$cggm->AddDynamicPoint($map,trim($param2[0]),'',$param2[0],'','',$param2[1]);

$smarty->assign('point1',implode(',',$cggm->GetCoordsFromAddress($param1[0])) );
$smarty->assign('point2',implode(',',$cggm->GetCoordsFromAddress($param2[0])) );

JanB
Last edited by janb on Sat Jun 12, 2010 11:28 am, edited 1 time in total.
antosha
Forum Members
Forum Members
Posts: 60
Joined: Fri Jun 06, 2008 7:20 pm

Re: CGGoogleMaps address to GLatLng

Post by antosha »

Thank you so much ! Everything works great :D
Follow me on twitter: end_tone
Linked In: levchenkoanton
Post Reply

Return to “Modules/Add-Ons”