Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.