Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com > PHP Calculate distance by Lat-Lon

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 10-11-2012, 04:57 AM PM User | #1 sonny Regular Coder     Join Date: Apr 2008 Location: United States Posts: 567 Thanks: 88 Thanked 0 Times in 0 Posts Calculate distance by Lat-Lon Hi Can someone please check this, the miles do not seem right when I test it PHP Code: ```     function distance(\$lat1, \$lng1, \$lat2, \$lng2, \$miles = true){     \$pi80 = M_PI / 180;     \$lat1 *= \$pi80;     \$lng1 *= \$pi80;     \$lat2 *= \$pi80;     \$lng2 *= \$pi80;           \$r = 6372.797; // mean radius of Earth in km     \$dlat = \$lat2 - \$lat1;     \$dlng = \$lng2 - \$lng1;     \$a = sin(\$dlat / 2) * sin(\$dlat / 2) + cos(\$lat1) * cos(\$lat2) * sin(\$dlng / 2) * sin(\$dlng / 2);     \$c = 2 * atan2(sqrt(\$a), sqrt(1 - \$a));     \$km = \$r * \$c;           return (\$miles ? (\$km * 0.621371192) : \$km); } \$lat1 = "39.9289";//Beijing China \$lon1 = "116.3883"; \$lat2 = "47.6026";//Seattle Washington \$lon2 = "-122.3284"; \$distance = distance(\$lat1, \$lon1, \$lat2, \$lon2); echo "They are ".\$distance." miles away from each other  ``` Last edited by sonny; 10-11-2012 at 06:10 AM..
 10-11-2012, 06:41 PM PM User | #2 sunfighter Senior Coder   Join Date: Jan 2011 Location: Missouri Posts: 3,269 Thanks: 23 Thanked 468 Times in 467 Posts Your php gives me They are 5400.5810531334 miles away from each other I used one from http://www.marketingtechblog.com/calculate-distance/ and got 5398.8 Miles. http://www.freemaptools.com/how-far-...jing_china.htm shows 5399.094 Miles. Remember: A man with one GPS unit knows exactly where he is. A man with two units is never sure.
10-11-2012, 07:25 PM   PM User | #3
sonny
Regular Coder

Join Date: Apr 2008
Location: United States
Posts: 567
Thanks: 88
Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by sunfighter Your php gives me They are 5400.5810531334 miles away from each other I used one from http://www.marketingtechblog.com/calculate-distance/ and got 5398.8 Miles. http://www.freemaptools.com/how-far-...jing_china.htm shows 5399.094 Miles. Remember: A man with one GPS unit knows exactly where he is. A man with two units is never sure.
I was just trying to double check the calculations within the script
Thanks
Sonny

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 01:36 PM.