Page 1 of 1

Adding Maps to an application

PostPosted: Thu Feb 23, 2012 12:52 pm
by wisni1rr
I just watched a video on youtube that had a simple example for having an embedded map.

http://youtu.be/HTm-3Cduafw

I was wondering if anyone could guide me as to how I could have the map display in the Xataface framework. I only need it to show up on 1 table's detail page. I'm not sure on the best placing of the map on the details page of a record. However, the map should be placed logically. (Note: the details page in question already has a PIC as a logo.

I'm playing around with it. I figured I would ask in case someone can solve this issue for me in second.

Thanks!

Re: Adding Maps to an application

PostPosted: Thu Feb 23, 2012 2:10 pm
by shannah
You can add custom sections to the view tab using section__sectionname()
http://xataface.com/wiki/How_to_Add_Cus ... o_View_Tab

That is probably the easiest place to add content to the view tab.

-Steve

Re: Adding Maps to an application

PostPosted: Thu Feb 23, 2012 3:05 pm
by wisni1rr
Thanks again, Steve!

I was wondering now how I could call the fields for the current record as variables. All the fields required to generate an address are in the same table that the delegate class resides.

I need theses fields (spelled as variables):
Code: Select all
$StreetNO, $StreetName, $City, $State, $Zip
and save them as a new variable
Code: Select all
$locationString = "$StreetNo,+$StreetName,+$City,+$State,+$Zip


So my delegate would be something like this:
Code: Select all
function section__Map(&$record){
    return array(
        'content' => <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo$locationString?>&amp;ie=UTF8&amp;hq=&amp;hnear=<?php echo $locationString;?>&amp;t=m&amp;z=14&amp;output=embed"></iframe>
        'class' => 'main',
        'label' => 'Property Map via Google'
    );
}

Re: Adding Maps to an application

PostPosted: Thu Feb 23, 2012 3:27 pm
by shannah
Code: Select all
$locationString = $record->val('StreetNo').','.$record->val('StreetName').','. ... etc....

Re: Adding Maps to an application

PostPosted: Thu Feb 23, 2012 3:36 pm
by wisni1rr
Can I use php on the 'content' array?

For example:

Code: Select all
  function section__map(&$record){
          return array(
           'content' => '$record->val("City")',
           'class' => 'main',
           'label' => 'Property Map via Google'
    );
}


My content will start off with traditional <html> tags but goes in and out of php a few times.

Re: Adding Maps to an application

PostPosted: Thu Feb 23, 2012 3:54 pm
by ADobkin
Yes, you can do that, but variables are not parsed inside of single quotes. Either change them to double quotes or remove them altogether, depending on what else you plan on adding to it.

Re: Adding Maps to an application

PostPosted: Thu Feb 23, 2012 4:07 pm
by wisni1rr
Thank you for pointing that out. I had forgotten that rule...

Re: Adding Maps to an application

PostPosted: Thu Feb 23, 2012 4:24 pm
by wisni1rr
The content I am using also contains some double quotes...

I tried switching the content to use single quotes instead. The application works. However, it behaves unexpectedly. When using double quotes, the details section becomes hidden. If you collapse the map section I have created, it will flicker between expanded and collapsed.

The following code works how I would like it to. The problem is it is not dynamic.

Code: Select all
function section__map(&$record){
          return array(
           'content' => '<iframe width="700" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=528+15TH+ST,+Port+Huron,+MI&amp;aq=&amp;sll=42.827639,-82.633667&amp;sspn=0.80171,1.234589&amp;ie=UTF8&amp;hq=&amp;hnear=528+15th+St,+Port+Huron,+Michigan+48060&amp;ll=42.978434,-82.441678&amp;spn=0.006248,0.009645&amp;t=m&amp;z=16&amp;output=embed"></iframe>',
           'class' => 'main',
           'label' => 'Property Map via Google'
    );
}


Removing the quotes all together will generate a Parse error: unexpected '<'.

Re: Adding Maps to an application

PostPosted: Fri Feb 24, 2012 12:11 pm
by wisni1rr
I figured it out. Here is my solution for anyone who was wondering:

Code: Select all
function section__map(&$record){
                $locationString = $record->val('StreetNo').' '.$record->val('StreetName').' '.$record->val('City').' '.$record->val('State');
                $locationString = urlencode($locationString);
          return array(
           'content' => "<iframe width='725' height='350' frameborder='1' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=$locationString&amp;ie=UTF8&amp;hq=&amp;hnear=$locationString&amp;t=m&amp;z=16&amp;iwloc=A&amp;output=embed'></iframe>",
           'class' => 'main',
           'label' => 'Property Map via Google'
    );
}