Jump to content

kilometer calculator


techker

Recommended Posts

... like the guy puts montreal to toronto it egals 1200 kilometers..

 

If that kind of 'accuracy' is good enough, just use a random number calculator.  'As the crow flies' it's around 500 km.

 

Unless you want to host an enormous database - and then you would only get the point-to-point distance not how far you actually travel - you could use a third-party service to provide the information.

 

http://www.google.com/search?q=distance+between+cities offers lots

Link to comment
https://forums.phpfreaks.com/topic/108119-kilometer-calculator/#findComment-554211
Share on other sites

Supposedly, this should do the trick. It isn't my code (I suck at math) and I haven't tested it, but give it a try.

 

$lat1 = 46.2341938036161; 
$lon1 = -63.124778021257015; 

$lat2 = 46.4141938036161; 
$lon2 = -63.118571124705284; 

$distance = (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180);

 

Of course you still need a database with coordinates.

Link to comment
https://forums.phpfreaks.com/topic/108119-kilometer-calculator/#findComment-554215
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.