# kilometer calculator

## Recommended Posts

hey guys i need to do a web site that hase a kilometer calculator?

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

does this exist already?if not is it doable?...lol

##### Share on other sites

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

##### 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.

##### Share on other sites

wow..ok you lost me what do i do with that.

but anyways i think im going to use google.thx

##### Share on other sites

It's a script that takes longitude and latitude of two locations and calculates the distance in KM. But you're right, if you don't know what to do with it, better use Google instead

##### Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

## Join the conversation

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.