0 Members and 1 Guest are viewing this topic.

*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Distance between Users
« on: September 13, 2017, 08:25:23 AM »
I know I have a lot of questions and I am very happy that you are helping me.
I'm also trying to give back as much as I can.

Now I have the question how to do this with the distance between two users, which it logs in in the profile and also in the small thumbnails after the login.

*

Pharg

  • *****
  • 2,793
    • OsDateFourm
  • osDate Version: osDate Evo v1.2
Re: Distance between Users
« Reply #1 on: September 13, 2017, 08:37:25 AM »
Hi Olaf,

Thanks and your welcome, I try to help as much as I can.

Opps my mistake I didn't read this correctly sorry.

I am not sure what you want to know?
« Last Edit: September 13, 2017, 08:39:54 AM by Pharg »
Regards,
Pharg ( Phill )

REMEMBER: ALWAYS BACKUP BEFORE YOU MAKE ANY CHANGES!!

osDateEvo v1.2 | PHP: 5.3.42 & PHP: 5.6.18 | MySQL: 5.5.35

*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Re: Distance between Users
« Reply #2 on: September 14, 2017, 06:04:38 AM »
Good morning Pharg

I would like to know how I can set it up so that one user can see how far away another is from him.

*

Pharg

  • *****
  • 2,793
    • OsDateFourm
  • osDate Version: osDate Evo v1.2
Re: Distance between Users
« Reply #3 on: September 14, 2017, 06:57:16 AM »
Hi olaf,

That would mean having to do some coding, I have never seem a mod on here like that on here before sorry.

You would have to learn the geo code, which needs updating a lot.
Regards,
Pharg ( Phill )

REMEMBER: ALWAYS BACKUP BEFORE YOU MAKE ANY CHANGES!!

osDateEvo v1.2 | PHP: 5.3.42 & PHP: 5.6.18 | MySQL: 5.5.35

*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Re: Distance between Users
« Reply #4 on: September 14, 2017, 07:08:54 AM »
Hi Pharg,

ok, i will give it a try. If i get solution, i will share it.

*

Pharg

  • *****
  • 2,793
    • OsDateFourm
  • osDate Version: osDate Evo v1.2
Re: Distance between Users
« Reply #5 on: September 14, 2017, 07:31:19 AM »
Ho olaf,

This is still using geo MaxMind 1 the new one is geo MaxMind 2, so finding the correct code might be hard.
Regards,
Pharg ( Phill )

REMEMBER: ALWAYS BACKUP BEFORE YOU MAKE ANY CHANGES!!

osDateEvo v1.2 | PHP: 5.3.42 & PHP: 5.6.18 | MySQL: 5.5.35

*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Re: Distance between Users
« Reply #6 on: September 14, 2017, 08:25:03 AM »
Hi Pharg,

i got a solution, but it is not working right. I get always the wrong distance. It should be 30 km, i get 5640 km ;-)

I post the Code, mayby someone got an idea.

######################################################
# Distance shown on the Users Profile
# Attention
# Is just working, if both user have entered all zip codes..

######################################################

Function
includes/internal/Functions.php
Add bevor ?>

Code: [Select]
function get_coords($plz)
{
if ( (!empty($plz)) && (strlen($plz) == 5) )
{
$query = mysql_query("SELECT latitude, longitude FROM " . ZIPCODES_TABLE . "  WHERE code LIKE '%". $plz ."%'");

$result = mysql_fetch_array($query);
echo mysql_error();
$coords[0] = $result['latitude'];
$coords[1] = $result['longitude'];
return $coords;
}
}

// Calculate the distance between the both zipcodes.
function distance($start_plz, $end_plz)
{
$erd_radius = 6378.388;

$start = get_coords($start_plz);
$end = get_coords($end_plz);

$x_start = $start[0] / 180 * M_PI;
$y_start = $start[1] / 180 * M_PI;

$x_end = $end[0] / 180 * M_PI;
$y_end = $end[1] / 180 * M_PI;

$e = acos( sin($x_start) * sin($x_end) + cos($x_start) * cos($x_end) * cos($y_start - $y_end) );
$dista = $e * $erd_radius;
$distance = explode(".", $dista);
$thedistance = $distance["0"];
  return $thedistance;
}

Show at Profile-> showprofile
showprofile.php

Add after
Code: [Select]
$user =& $osDB->getRow('SELECT id, username etc
this

Code: [Select]
// Distance Hack
if ( $_SESSION[UserId] != '' ) {
    $src_zip = $osDB->getOne('select zip from ! where id = ?', array(USER_TABLE, $_SESSION[UserId] ) );
    $t->assign('src_zip', $src_zip);

    $src_latitude = $osDB->getOne('select zip_latitude from ! where id = ?', array(USER_TABLE, $_SESSION[UserId] ) );
    $t->assign('src_latitude', $src_latitude);

    $dest_latitude = $osDB->getOne('select zip_latitude from ! where id = ?', array(USER_TABLE, $_REQUEST['id'] ) );
    $t->assign('dest_latitude', $dest_latitude);
   
}
if (!empty($src_latitude) and !empty($dest_latitude)) {
$user['distance'] = distance($user['zip'], $src_zip);
}
// End Distance Hack

Template
nickpage_basic_address.tpl
Where ever you want it

My template is OsDMix

Code: [Select]
{if $user.distance != '' AND ( $smarty.session.UserId != $user.id ) }
<div class="p-sec-row">
<div class="clearfix">
<div class="pro-sec-q">{lang mkey='zodiac_sign'}Entfernung:</div>
            <div class="pro-sec-a">ca. {$user.distance} km</div>
</div>
</div>
    {else}
    <div class="p-sec-row">
<div class="clearfix">
<div class="pro-sec-q">{lang mkey='zodiac_sign'}Entfernung:</div>
            <div class="pro-sec-a">Unbekannt</div>
</div>
</div>
  {/if}

*

Pharg

  • *****
  • 2,793
    • OsDateFourm
  • osDate Version: osDate Evo v1.2
Re: Distance between Users
« Reply #7 on: September 14, 2017, 09:31:43 AM »
Hi Olaf,

Thanks but when sharing the code, using OsDMix template is no good to use, you need to show it in a default template.

This line:
Code: [Select]
$user =& $osDB->getRow('SELECT id, username etc
Should be:
Code: [Select]
$user = $osDB->getRow('SELECT id, username etc
As the =& has depreciated since PHP 5.3
Regards,
Pharg ( Phill )

REMEMBER: ALWAYS BACKUP BEFORE YOU MAKE ANY CHANGES!!

osDateEvo v1.2 | PHP: 5.3.42 & PHP: 5.6.18 | MySQL: 5.5.35

*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Re: Distance between Users
« Reply #8 on: September 14, 2017, 09:49:45 PM »
Hi Pharg,

the problem isnt unfortunaly the part of code you mean.

It must be something else.

When it is working, i will post the code for the default template.



*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Re: Distance between Users
« Reply #9 on: September 15, 2017, 06:37:42 AM »
I'm beginning to think there's something wrong with the zip code file.
I'll attach the file

*

Pharg

  • *****
  • 2,793
    • OsDateFourm
  • osDate Version: osDate Evo v1.2
Re: Distance between Users
« Reply #10 on: September 15, 2017, 07:37:36 AM »
Hi olaf,

All the zip codes where updated by a member not log ago, so I won't be changing them again.

The geoip needs to be updated, that is probably where the issue is and the geo has never been accurate in osdate.
Regards,
Pharg ( Phill )

REMEMBER: ALWAYS BACKUP BEFORE YOU MAKE ANY CHANGES!!

osDateEvo v1.2 | PHP: 5.3.42 & PHP: 5.6.18 | MySQL: 5.5.35

*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Re: Distance between Users
« Reply #11 on: September 15, 2017, 07:58:56 AM »
Ok, now a stupid question, wher ist the geoip to find.

*

Pharg

  • *****
  • 2,793
    • OsDateFourm
  • osDate Version: osDate Evo v1.2
Re: Distance between Users
« Reply #12 on: September 15, 2017, 08:35:38 AM »
Regards,
Pharg ( Phill )

REMEMBER: ALWAYS BACKUP BEFORE YOU MAKE ANY CHANGES!!

osDateEvo v1.2 | PHP: 5.3.42 & PHP: 5.6.18 | MySQL: 5.5.35

*

Olaf Klausen

  • *
  • 44
  • osDate Version: osDate v2.7
Re: Distance between Users
« Reply #13 on: September 16, 2017, 11:18:04 AM »
Great, but how have i got to use it

*

Pharg

  • *****
  • 2,793
    • OsDateFourm
  • osDate Version: osDate Evo v1.2
Re: Distance between Users
« Reply #14 on: September 16, 2017, 11:33:47 PM »
Hi olaf,

it has to replace the old version of geoip.

Will look at it some time, it's not a easy project, that's why it hasn't been done yet.
Regards,
Pharg ( Phill )

REMEMBER: ALWAYS BACKUP BEFORE YOU MAKE ANY CHANGES!!

osDateEvo v1.2 | PHP: 5.3.42 & PHP: 5.6.18 | MySQL: 5.5.35