Geo Location in accounts (when creating an account)

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

By Zicky - 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 Zicky - 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 Zicky - December 2, 2015

Hey Equinox,

I'm not using Geocoder for the solution, but instead loading the LatLng directly into a URL that queries Google Maps (launched into a new browser window) once the link is clicked. Have a look at the code below... you can replace the <?php echo...> with some geo LatLng coordinates ( 40.7127  -74.0059 ) and see the results.

<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>

Hope that helps clarify what and how I'm using it.

Zick

By Codee - December 2, 2015

Greetings Zicky,

Thank you for clarifying that!

Cheers!

By Twocans - December 7, 2015

great post thanks

Kenny