This is suppose to find the closest person to a specific address, if there is no user in the area then it is suppose to find how far the closest user is from that address. This has found the closest person and has found the closest distance for when there is no person in the area, however it has also failed to find the closest person and has just found the closest out of the area. I'm hoping there's just something wrong with my if statments that I'm not seeing. The $location_lat and $location_lng is the address of the location, $user_lat and $user_lng come from the database and are all the people's locations. $increase is set in the while loop when getting the peoples locations and contains the number of people in the database. $distallowed is the person area. $statment is set to 0 and is suppose to be my trigger that there is a person in the locations address i think this is where my problem is but don't know why it would not be being set or be cleared? Thanks for any help you can offer.
PHP Code:
while ($increase > $increase2 ) {
$value[] = 3959 * acos( cos((( $location_lat* 3.14159 )/180)) * cos((( $user_lat[$increase2] * 3.14159 )/180) ) * cos((($user_lng[$increase2]* 3.14159 )/180) - (($location_lng* 3.14159 )/180) ) + sin( (($location_lat* 3.14159 )/180) ) * sin((( $user_lat[$increase2] * 3.14159 )/180))) ;
if ($value[$increase2] - $distallowed[$increase2] < 0) {
$statment++;
$users_in_area[$increase2] = $value[$increase2];
}
else {
$users_in_area[$increase2]= $value[$increase2] - $distallowed[$increase2];
}
$increase2++;
}
$val=min($users_in_area);
$key=array_search($val, $users_in_area);
$total = substr($value[$key],0,6);
if ($statment > 0) {
echo "Closest person is $total miles from the location. Below is the contact info for <strong>$Name[$key]</strong>.";
} else if ($statment === 0) {
echo "There is no one in this locations area. The closest person is $Name[$key] and is $total miles from the address. ";
}
I got the equation there from google http://code.google.com/apis/maps/articles /phpsqlsearch.html.
Bookmarks