tomdelonge Posted March 6, 2010 Share Posted March 6, 2010 I can calculate the distance just fine (I found a tutorial that explained it quite well), but I also need to be able to calculate the driving distance between two points. I don't know how accurate it would have to be, but I can't figure out how to do it. Any ideas on where to start? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/194367-how-would-you-calculate-mileage-between-two-cities/ Share on other sites More sharing options...
Mchl Posted March 6, 2010 Share Posted March 6, 2010 Grab it from Google Maps? Quote Link to comment https://forums.phpfreaks.com/topic/194367-how-would-you-calculate-mileage-between-two-cities/#findComment-1022453 Share on other sites More sharing options...
Zane Posted March 6, 2010 Share Posted March 6, 2010 I can calculate the distance just fine (I found a tutorial that explained it quite well),............ Any ideas on where to start? Thanks. This is basic math... the most basic of basic if you ask me. Think about it. If it is 100 miles between two points, the only other variable that you need is the speed. The paradox that you'll run into is that.. obviously no one will ever be going a constant speed for an entire 100 miles. That's impossible. You've got dynamics to look at such as [ot] - the posted speed limits - the mileage/condition of the car itself - the weather - the tire pressure - the number of passengers AKA the weight of the car - the alcohol level of the driver - the chance of a wreck - slow drivers in front of you - back seat drivers ruining your focus - slowing down to change the radio station... --- it can go on and on [/ot] but all it really boils down to is a relative speed.. You could get all fancy and use sin waves and such if you wanted... but to start off simple. If you're traveling 65 mph to a distance 100 miles away, how long do you think that would take? Well.. If you can 65 miles in 1 hour.. You should be able to get 100 miles in (100 / 65) hours ........which is 1.54 Quote Link to comment https://forums.phpfreaks.com/topic/194367-how-would-you-calculate-mileage-between-two-cities/#findComment-1022456 Share on other sites More sharing options...
tomdelonge Posted March 7, 2010 Author Share Posted March 7, 2010 Sorry, maybe I didn't explain it well enough. The distance, not how long it takes to get there. And I'm talking through php, not just by looking it up online each time. I'll have a bunch of zip codes in the database, but I want to be able to find the approximate driving distance between any two. Quote Link to comment https://forums.phpfreaks.com/topic/194367-how-would-you-calculate-mileage-between-two-cities/#findComment-1022713 Share on other sites More sharing options...
premiso Posted March 7, 2010 Share Posted March 7, 2010 I'll have a bunch of zip codes in the database, but I want to be able to find the approximate driving distance between any two. lol You are better off looking it up online. What you need to do is find the latitude and longitude for each ZipCode, after you have that find out how many degrees is considered a mile. Once you have that you should be able to calculate it no problem! The point, you have to have 2 absolute positions and have a way to calculate the distance between two points. Without having or knowing 2 absolute positions, how do you expect to calculate the distance (other then by driving there yourself and doing an average speed etc, which Zane hit on)? Quote Link to comment https://forums.phpfreaks.com/topic/194367-how-would-you-calculate-mileage-between-two-cities/#findComment-1022719 Share on other sites More sharing options...
Zane Posted March 8, 2010 Share Posted March 8, 2010 Here, I'll let you in on a super secret.. (passed down from generation to generation) thread/topic that deals about this very question you have asked. If that doesn't help you out, then I'd recommend premiso's suggestion... manually checking it through Google Maps.. (I highly doubt you'll need to though) http://www.phpfreaks.com/forums/index.php/topic,208965.0.html Quote Link to comment https://forums.phpfreaks.com/topic/194367-how-would-you-calculate-mileage-between-two-cities/#findComment-1022882 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.