Google maps

Archived from the Xataface Users forum.

tomhousley — Tue Aug 04, 2009 2:08 am

Hello,

I would like to be able to populate a google map with records from a table called tbl_organisations

I have this working fine in PHP outside of xataface, but I can’t get the map (even a basic one without any markers pulled from an php generated XML file.

my actions.ini looks like this:

Code: Select all
[map]     label = Map     category = table_tabs     mode = map     url = "{$this->url('-action=map')}"     template = Map_View.html     condition = "$query['-table']=='tbl_organisations'"

my map.php file looks like this:

Code: Select all
<?php class actions_map {     function handle(&$params){         df_display(array(), 'Map_View.html');     } } ?>

my Map_View.html file without any google maps stuff looks like this:

Code: Select all
`{use_macro file=”Dataface_Main_Template.html”}
    {fill_slot name=”main_section”}

Some text

    {/fill_slot}
{/use_macro}`

The google maps code from http://code.google.com/apis/maps/docume … ction.html looks like this:

Code: Select all
`<!DOCTYPE html “-//W3C//DTD XHTML 1.0 Strict//EN”
  “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>           Google Maps JavaScript API Example     <script src="http://maps.google.com/maps?file=api&v=2&key=MYGOOGLEMAPSKEY=true_or_false"             type="text/javascript"></script>            
 

`

I have tried many ways of putting this into Map_View.html without any success.

I would be grateful if someone could show me how the google maps code above can be incorporated into my map tab / Map_View.html

Many thanks, Tom


shannah — Tue Aug 04, 2009 9:20 am

A couple of points:

  1. You either need to use the template directive in the actions.ini file, or define a custom action class. But not both. The custom action class overrides the template directive. So you could just skip the whole actions_map class, and just rely on the template=Map_View.html directive to use the correct template.

  2. Smarty probably doesn’t like the { and } javascript brackets. But don’t despair. All you have to do is wrap the javascript in {literal}{/literal} tags to tell smarty to ignore the javascript.

Your Map_View.html file would look like:

Code: Select all
`{use_macro file=”Dataface_Main_Template.html”}
    {fill_slot name=”main_section”}

   
    <div></div>
    {/fill_slot}
{/use_macro}`

The registerPloneFunction() call is instead of the body onload=”..” tag. It registers the initialize function to be run when the window is finished loading. You could also just use window.onload=initialize; However this may overwrite an existing onload handler.