WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : greatcircle.php Convert latitude/longitude coordinates between degree and decimal format. Also has ability to determine distance between them.
Categories : Algorithms, PHP Click here to Update Your Picture
Doug Pillow
Date : Feb 27th 2003
Grade : 3 of 5 (graded 8 times)
Viewed : 29761
File : greatcircle.php
Images : No Images for this code example.
Search : More code by Doug Pillow
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
//degree format 1218'6" degrees minutes' seconds"
//decimal format 121.135
//accepts a coordinate in degree format and returns the equivalent decimal
//N & S are latitudes
//E & W are longitudes
//South latitudes and West longitudes are negative decimals
//calling examples
//degree2decimal('12186"N'); returns 121.135
//degree2decimal('12186"S'); returns -121.135
//degree2decimal('12186"E'); returns 121.135
//degree2decimal('12186"W'); returns -121.135
function degree2decimal($deg_coord="")
{
$dpos=strpos($deg_coord,'');
$mpos=strpos($deg_coord,'');
$spos=strpos($deg_coord,'"');
$mlen=(($mpos-$dpos)-1);
$slen=(($spos-$mpos)-1);
$direction=substr(strrev($deg_coord),0,1);
$degrees=substr($deg_coord,0,$dpos);
$minutes=substr($deg_coord,$dpos+1,$mlen);
$seconds=substr($deg_coord,$mpos+1,$slen);
$seconds=($seconds/60);
$minutes=($minutes+$seconds);
$minutes=($minutes/60);
$decimal=($degrees+$minutes);
//South latitudes and West longitudes need to return a negative result
if (($direction=="S") or ($direction=="W"))
        { $decimal=$decimal*(-1);}
return $decimal;
}


//accepts a coordinate in decimal format and returns the equivalent degree
//as a string
//calling examples
//decimal2degree('121.135,'LAT'); will return 12186"N
//decimal2degree('-121.135,'LAT'); will return 12186"S
//decimal2degree('121.135,'LON'); will return 12186"E
//decimal2degree('-121.135,'LON'); will return 12186"W
function decimal2degree($decimal_coord="",$latorlon="")
{
//121.135
//degrees=121
//minutes=.135*60=(8).1
//seconds=.1*60=(6)
//12186"
$decpos=strpos($decimal_coord,'.');
$whole_part=substr($decimal_coord,0,$decpos);
$decimal_part=abs($decimal_coord-$whole_part);
$minutes=intval($decimal_part*60);
$seconds=intval((($decimal_part*60)-$minutes)*60);
if ($latorlon=='LAT')
        {if ($whole_part<0)
                {
                $whole_part=($whole_part*(-1));
                $L='S';
                }
        else
                {
                $L='N';
                }
        }//end if
else
        {if($latorlon=='LON')
                {if ($whole_part<0)
                        {
                        $whole_part=($whole_part*(-1));
                        $L='W';
                        }
                else
                        {
                        $L='E';
                        }
                }//end if
        }//end if
$degree=$whole_part.''.$minutes.''.$seconds.'"';
$degree.=$L;
return $degree;
}

//accepts two decimal latitude, longitude coordinates and returns the distance
//between the two
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);
}

//accepts two degree latitude, longitude coordinates and returns the distance
//between the two
function degree_distance($lat1="",$lon1="",$lat2="",$lon2="")
{
$lat1=degree2decimal($lat1);
$lat2=degree2decimal($lat2);
$lon1=degree2decimal($lon1);
$lon2=degree2decimal($lon2);
$distance=decimal_distance($lat1,$lon1,$lat2,$lon2);
return $distance;
}


?>

See it in action at http://www.geoarmy.com/distance_calculation/



what salt do I have to feed the crypt function with to make it work like the htpasswd command of apache?
Categories : Algorithms, PHP, Authentication
Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users).
Categories : Algorithms, Email, PHP
A recursive function to traverse a multi-dimensional array where the dimensions are not known
Categories : Arrays, PHP, Algorithms
The Porter Word Stemming Algorithm in PHP Reduces words to their base stem for search engines and indexing
Categories : Algorithms, PHP, Strings
A simple bubblesort that takes 2 arrays as argument.The first one is the actual data used for sorting, the second is data that will "tag along" with the first array, for instance a descriptive text about the data in the first array.
Categories : Algorithms, Arrays, PHP, Complete Programs
How to validate an Israeli ID number.
Categories : Ecommerce, PHP, Algorithms
These 2 functions write and read the contents of a specially designated multi-dimensional array to and from a text file.
Categories : Algorithms, PHP, Filesystem
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
textwrap fill-paragraph (justification)
Categories : Strings, PHP, Algorithms
Dollar Serial Number Validator
Categories : PHP, Security, Algorithms
Calculate the great circle distance between two latitude/longitudes
Categories : Algorithms, PHP
Boolean Keyword Interpreter
Categories : PHP, Algorithms, Search Engines
Prime number finder (Sieve of Erastothenes)
Categories : PHP, Algorithms, Math.
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge response login algorithms over an insecure connection.
Categories : Algorithms, PHP, Security
 Daniel Boos wrote :1249
//radius is circumference/(2*pi) which gives us 6637km or 3956miles

6637km is wrong it`s ~6367km