budimir Posted October 12, 2008 Share Posted October 12, 2008 Hey guys, I'm creating a script where I should display distances between two cities. User can choose From - To cities and then distance is displayed For example: City 1 -> City2 = 56km City55 -> City72 = 110km ... In my DB I have this fields: ID date from_city to_city distance How do I calculate which is distance from one city to another??? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 12, 2008 Share Posted October 12, 2008 Can you post, perhaps, 5 database entries and then the two cities you want the distance between to give us a working example to think off of? Quote Link to comment Share on other sites More sharing options...
budimir Posted October 12, 2008 Author Share Posted October 12, 2008 Here it is: ID From To Distance 1 Zagreb Karlovac 52Km 2 Zagreb Knin 274Km 3 Zagreb Virovitica 154Km 4 Zagreb Split 374Km 5 Karlovac Pula 234Km These are values from DB. I'm not sure how to calculate distance (for example) from Karlovac to Knin??? And other combinations?? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 12, 2008 Share Posted October 12, 2008 With this data it isn't possible to calculate the distance from karlovac to knin. You would need to use the angle between the triangle knin/zagreb/karlovac along with the law of cosines to find the distance... Unfortunately since you don't have the angle it's impossible to tell. Quote Link to comment Share on other sites More sharing options...
budimir Posted October 12, 2008 Author Share Posted October 12, 2008 That's what I thought. I thought that maybe there is a way. Thanks a lot for your help. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 12, 2008 Share Posted October 12, 2008 It would also be doable if you could triangulate the position of the two points from 3 locations (eg if you had 2 locations other than zagreb that had their distances from knin and karlovac), but this would be a fairly advanced technique. Quote Link to comment 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.