Geo Location in accounts (when creating an account)

9 posts by 4 authors in: Forums > CMS Builder
Last Post: December 7, 2015   (RSS)

By Mikey - October 26, 2015

I'd like add a link to Google Maps to show the geo-location of the user's account powered by geocoded, latitude and longitude.

The code is placed in a --- separator --- as HTML

The code below works only after an account is created and if the user has an address to generate the latitude and longitude coordinates. I'm sure there's a much better way to write this code to achieve the same results as well - if anyone has suggestions.

So here's the code:

<tr>
 <td colspan='2'>
<?php
  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('/home/contents/ab/12345678/html/domain/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load record from 'accounts'
  list($accountsRecords, $accountsMetaData) = getRecords(array(
    'tableName'   => 'accounts',
    //'where'       => '', // load first record
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $accountsRecord = @$accountsRecords[0]; // get first record
  if (!$accountsRecord) { dieWith404("Record not found!"); } // show error message if no record found
?> 
<?php if ($accountsRecord['latitude']): ?>
<a href="https://www.google.com/maps/place/@<?php echo htmlencode($accountsRecord['latitude']) ?>,<?php echo htmlencode($accountsRecord['longitude']) ?>,15z/data=!4m2!3m1!1s0x0:0x0" target="_blank">Geo Location</a>
<?php endif; ?>
</td>
</tr>

The problem with this is that if an Admin is creating a user account from scratch and nothing exist in relationship to a save user account - the following error is produced.

Warning: Cannot modify header information - headers already sent by (output started at /home/contents/ab/12345678/html/domain/cmsb/lib/menus/header.php:13) in /home/contents/ab/12345678/html/domain/cmsb/lib/common.php on line 1092 Record not found!

Anyone have any suggestions on how to eliminate the "Warning" message that's produced if creating a new user account from scratch, and if you have a suggestion on a better way to write the code for the geo-location of the user's account - please let me know.

Many thanks in advance!

Zick

By Damon - October 27, 2015

HI Zick,

Remove this line of code and the error message will be eliminated:

  if (!$accountsRecord) { dieWith404("Record not found!"); } // show error message if no record found

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Damon - October 27, 2015

HI Zick,

Remove this line of code and the error message will be eliminated:

  if (!$accountsRecord) { dieWith404("Record not found!"); } // show error message if no record found

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Mikey - October 27, 2015 - edited: October 27, 2015

Okay - I fell really stupid now : )

Thanks Damon... working perfectly now.

By Damon - October 27, 2015

No problem.  I often ask Ross to take a look at my code when I have trouble locating an error. A fresh pair of eyes really helps.

Glad it is working now!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Codee - December 2, 2015

Hi Zicky,

I found your post here very interesting and I think it's what a client is going to need so, if you don't mind, let me ask a clarifying question or two...

Are you using the Geocoder plugin to create google map links for multiple accounts?  So, if you have 100 clients with accounts on said site, each client's php/html page would show their googlemap?

Have you had any challenges doing this...such as the geocoder possibly wanting to only provide googlemap info for just one account even though you have multiple accounts?

Thanks!

Equinox

By Codee - December 2, 2015

Greetings Zicky,

Thank you for clarifying that!

Cheers!

By Twocans - December 7, 2015

great post thanks

Kenny