Skip to Content Skip to Menu

Distance user searching, without a postal code

  • sstark
  • sstark
  • OFFLINE
  • Posts: 86
  • Thanks: 0
  • Karma: 0
17 years 8 months ago #30936 by sstark
I wrote an article on how to achieve this, and I thought the community would enjoy the read.

I wanted to be able to search my users by x Km without the need to process postal / zip codes. I achieved this in one day by incorporating some new components for mapping and searching.


read the Full Story

StevenStark.com - Work | Smart-Love.ca - Dating

Please Log in or Create an account to join the conversation.

17 years 8 months ago #30951 by KurtSteiner
Replied by KurtSteiner on topic Re:Distance user searching, without a postal code
Hello sstark,

I read your article and I`m interested in testing your solution.

Where can i get detailed informations?

sunny regards from Germany

BERND (Kurt Steiner)

Please Log in or Create an account to join the conversation.

  • sstark
  • sstark
  • OFFLINE
  • Posts: 86
  • Thanks: 0
  • Karma: 0
17 years 8 months ago #30975 by sstark
considering it involved a fair bit of custom hacking, I just wrote the theory and no actual examples... maybe I can improve on that?

1.) have Joogle working properly with GeoCoder
2.) add Fields in CB designed to restrict the search (like Distance in Km)
3.) After your search executes its SQL, filter the search results by the options in CB. You will have to manually edit the search's php for this. I will copy the long / lat to Km script I used:

[code:1]function decimal_distance($lat1="",$lon1="",$lat2="",$lon2=""«»)
{
//$radius is determined using the following formula
//(360 degrees)*(60 minutes per degree)*(1.852) km per minute
//give a circumference of 40003.2 km
//radius is circumference/(2*pi) which gives us 6637km or 3956miles
$radius=3956;
$lat1 = deg2rad ($lat1);
$lat2 = deg2rad ($lat2);
$lon1 = deg2rad ($lon1);
$lon2 = deg2rad ($lon2);
//Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine",
//Sky and Telescope, vol. 68, no. 2, 1984, p. 159):
$dlon=$lon2-$lon1;
$dlat=$lat2-$lat1;
$sinlat=sin($dlat/2);
$sinlon=sin($dlon/2);
$a=($sinlat*$sinlat)+cos($lat1)*cos($lat2)*($sinlon*$sinlon);
$c=2*asin(min(1,sqrt($a)));
$d=$radius*$c;
//
return round($d,2);
}[/code:1]

let me know if you need more help.

StevenStark.com - Work | Smart-Love.ca - Dating

Please Log in or Create an account to join the conversation.

17 years 8 months ago #30976 by KurtSteiner
Replied by KurtSteiner on topic Re:Distance user searching, without a postal code
:kiss:

Many thanks,
I will have to check this out.

I'm very interested because just starting a similar project and looking for interesting features.

The point i miss is the matching search where i can chose like

"female looking for male"

"age between 36 and 63:S "

"distancce less than 50km"

...

Will also check out your site soon :silly:

sunny regards from Germany

BERND (Kurt Steiner)

Please Log in or Create an account to join the conversation.

  • sstark
  • sstark
  • OFFLINE
  • Posts: 86
  • Thanks: 0
  • Karma: 0
17 years 8 months ago #30977 by sstark
oh I forgot about age range, thanks! ;)

and the point you're missing is that the user has to set these search parameters in their CB settings, then it is saved.

This is not as obvious as other searches, however it does allow you now filter other modules. On my site I use these settings for the top avatar scroller and the user search.

StevenStark.com - Work | Smart-Love.ca - Dating

Please Log in or Create an account to join the conversation.

  • sstark
  • sstark
  • OFFLINE
  • Posts: 86
  • Thanks: 0
  • Karma: 0
17 years 8 months ago #30983 by sstark
here is my example of modifying the SQL result array $users in the search php with my filters. Keep in mind this is the rough draft ;)

[code:1]$users=$database->loadObjectList();


global $my;

$database->setQuery("SELECT cb_distance FROM #__comprofiler WHERE id=$my->id"«»);
$distance = $database->loadResult();
if($distance == ""«»){$distance = 40000000;}


$database->setQuery("SELECT cb_onlysex FROM #__comprofiler WHERE id=$my->id"«»);
$my_scroll_sex = $database->loadResult();

$database->setQuery("SELECT cb_onlineonly FROM #__comprofiler WHERE id=$my->id"«»);
$my_online_only = $database->loadResult();


$query = "SELECT lat FROM #__comprofiler WHERE id=$my->id";
$database ->setQuery ($query);
$my_lat = $database->loadResult();

$query = "SELECT lon FROM #__comprofiler WHERE id=$my->id";
$database ->setQuery ($query);
$my_lon = $database->loadResult();

$count = 0;
$temp = array();
$temp = $users;
foreach($users as $user) {
$query = "SELECT lat FROM #__comprofiler WHERE id=$user->id";
$database ->setQuery ($query);
$lat = $database->loadResult();

$query = "SELECT lon FROM #__comprofiler WHERE id=$user->id";
$database ->setQuery ($query);
$lon = $database->loadResult();

$query = "SELECT cb_gender FROM #__comprofiler WHERE id=$user->id";
$database ->setQuery ($query);
$gender = $database->loadResult();

$my_distance = decimal_distance2($my_lat, $my_lon, $lat, $lon);

$query = "SELECT time FROM #__session WHERE userid=$user->id";
$database ->setQuery ($query);
$my_session = $database->loadResult();

//echo $user->id.">".$my_session."<br />";
//echo $my_distance;
//restrict checks
$trigger = false;
if($my_distance > $distance){
//echo "<br />";
//echo "Deleting:".$user->username." for distance<br />";
$trigger = true;
}
if ($my_session == ""«»){
if($my_online_only == 1){
//echo "Deleting:".$user->username." for offline<br />";
$trigger = true;
}
}
if (($gender != $my_scroll_sex) and isset($gender)){
//echo $gender."<>".$my_scroll_sex."<br />";
//echo "Deleting:".$user->username." for Sex: ".$gender."<>".$my_scroll_sex."<br />";
$trigger = true;
}

if ($trigger == true){
unset($temp[$count]);
}
$count++;
}
$users = $temp;
unset($temp);
[/code:1]

StevenStark.com - Work | Smart-Love.ca - Dating

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum