Irish SEO,  Marketing & Webmaster Discussion

 

Calculating a distance in miles between 2 coordinates

This is a discussion on Calculating a distance in miles between 2 coordinates within the Webmaster Discussion forums, part of the Webmaster Help category; Hi, I have been asked to build a site where users would search for a type of business within a ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Webmaster Discussion

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 26-01-2007, 04:54 PM
Frontpage User
 
Join Date: Jan 2007
Location: Navan, Co Meath
Posts: 28
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
oliflorence will become famous soon enough
Default Calculating a distance in miles between 2 coordinates

Hi,
I have been asked to build a site where users would search for a type of business within a ?? number of miles from X point, let say 20 miles radius from Kildare for instance.
If I have a database of towns / cities with their respective coordinates, does any one know a way to run this search??, well the theory beind it!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 26-01-2007, 06:03 PM
RedCardinal's Avatar
Richard Hearne
Recent Blog: Irish Banks In UK
 
Join Date: Feb 2006
Posts: 941
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
RedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to behold
Default

Not sure on the technicalities of this, but you might find some info on how the search engines do it for their local services by heading over to seobythesea.com. It's a site run by Bill Slawski that contains info on patents awarded to the SEs. You might find something there and if not try dropping Bill an email - he seems like a pretty cool guy.
__________________
Search Engine Optimisation - Red Cardinal Internet Marketing
Internet Consultant Ireland | Search Engine Optimisation Services
Catering Company Dublin - My sister's handmade canape company!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 26-01-2007, 06:37 PM
blacknight's Avatar
Web Slave
 
Join Date: Jan 2006
Location: Ireland
Posts: 6,260
blacknight is a splendid one to beholdblacknight is a splendid one to beholdblacknight is a splendid one to beholdblacknight is a splendid one to beholdblacknight is a splendid one to beholdblacknight is a splendid one to beholdblacknight is a splendid one to behold
Send a message via ICQ to blacknight Send a message via AIM to blacknight Send a message via MSN to blacknight
Default

It would be really cool if the property sites started offering that kind of service.

I honestly don't care which county a house is located in - I'm only interested in the distance from it to my office
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 26-01-2007, 06:41 PM
RedCardinal's Avatar
Richard Hearne
Recent Blog: Irish Banks In UK
 
Join Date: Feb 2006
Posts: 941
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
RedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to beholdRedCardinal is a splendid one to behold
Default

I'm pretty sure the new ask.com local service (cant remember the name...) allows this.

Most of the local services are tied into mapping now and you can map your route with distances given. Of course that's for the US, so we can expect similar for Ireland in, um, well, in about 10 years or so
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 26-01-2007, 06:41 PM
daviddoran's Avatar
Wannabe Geek
Recent Blog: Joost
 
Join Date: Aug 2006
Location: Meath, Ireland
Posts: 342
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
daviddoran will become famous soon enough
Default

If you have the longtitude and latitude then google something like "calculating longtitude latitude distance".
It is basically Pythagorean math, and then changing to miles.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 26-01-2007, 06:58 PM
kae's Avatar
kae kae is offline
Byte Wrangler
 
Join Date: Sep 2006
Location: monaghan
Posts: 54
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
kae will become famous soon enough
Default

There was a post about something similar over at Pete Freitag's website:
Calculating Distance in Miles from Latitude and Longitude

Basically, you can use Pythagorus's theory as suggest by David (the link above shows a way), as long as the Longitudinal lines are relatively similar at the northenmost and southernmost latitudes that you will be considering.

Otherwise, you need to use more complex trigonometry to account for the curvature of the earth, as shown in this page:
Distance Calculation latitude longitude global database lists
__________________
verens.com, webworks.ie
kfm.verens.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 29-01-2007, 09:42 AM
Frontpage User
 
Join Date: Jan 2007
Location: Navan, Co Meath
Posts: 28
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
oliflorence will become famous soon enough
Default

Thanks guys,
will give this a go shortly
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 09-03-2007, 08:35 AM
kae's Avatar
kae kae is offline
Byte Wrangler
 
Join Date: Sep 2006
Location: monaghan
Posts: 54
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
kae will become famous soon enough
Default

I just found a very cool related trick.

Suppose you need to find all locations that are within 'n' kilometers of [x,y]. The "mostly accurate" way (ignoring the latitude problem) to do it is to "select * from locations where sqrt((x-@x)*(x-@x)+(y-@y)*(y-@y)) < @n". However, that's very slow, as you're doing math on every row of the database.

instead, you search within a bounding rectangle which is the same height/width as the n*2. This involves simple < and > checks. The result set from that will be very small, allowing you to do the accurate query on just the results. Very fast indeed.

If you have a recent MySQL (or any other db), you can do the bounding rectangle query as a subquery of the main one, letting you do a very fast check in one line!

The original article is here: Arjen's Journal - Great circle and distances
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
calculating, coordinates, distance, miles

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 02:28 PM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0