Distance Calculations - Best way to speed it up
Posted: Tue Jul 05, 2005 8:16 am
Hi, my first post on these forums, I hope somebody is able to help me :
I have a database with longitude and latitude coordinates. I also have 3 other databases of other items that also have longitude/latitude coordinates to them.
Now i want to compare all the lon/lat values from the first dataset, and then show the nearest data for the other databases.
To explain better I will tell you what im doing :
I have a directory of campsites.
I have a directory of pubs, days out, and bed and breakfast locations.
So, for the details on a campsite i want to have a box that says "the nearest pub is" + * name, number of miles away*
Now this seems to me to be extremly server intensive stuff, i have to loop through all the coordinates and output distances between them, then go back through the data and check distances to find the smalles amount. So, my question (finally!) is how to go about it? Is this the only way i can do this? How can i speed it up? Am i way off with my theory?
And lastly anybody know of any tutorials that will help with this? (especially regarding creating a temporary table that will hold the distance between coordinates, which i will later check through again and find the closest distance in miles)
It seems that im probably not up to the task on this one (pretty new to php) but I really want to do it... :S
I have a database with longitude and latitude coordinates. I also have 3 other databases of other items that also have longitude/latitude coordinates to them.
Now i want to compare all the lon/lat values from the first dataset, and then show the nearest data for the other databases.
To explain better I will tell you what im doing :
I have a directory of campsites.
I have a directory of pubs, days out, and bed and breakfast locations.
So, for the details on a campsite i want to have a box that says "the nearest pub is" + * name, number of miles away*
Now this seems to me to be extremly server intensive stuff, i have to loop through all the coordinates and output distances between them, then go back through the data and check distances to find the smalles amount. So, my question (finally!) is how to go about it? Is this the only way i can do this? How can i speed it up? Am i way off with my theory?
And lastly anybody know of any tutorials that will help with this? (especially regarding creating a temporary table that will hold the distance between coordinates, which i will later check through again and find the closest distance in miles)
It seems that im probably not up to the task on this one (pretty new to php) but I really want to do it... :S