views:

44

answers:

3

I have multiple addresses recorded in my database and I've used the Google Geocoding service to get their longitude, latitude, etc.

What do I need to do to calculate the proximity of one address from another in miles?

Ideally I want to show an entry and then say below it: "The following recorded addresses are close by."

+1  A: 

see http://www.movable-type.co.uk/scripts/latlong.html for example.

In meter:

D_AB = 6378137 * acos( cos(PI/ 180 * latA) * cos(PI/ 180 * lngA) * 
  cos(PI/ 180 * latB) * cos(PI/ 180 * lngB) + cos(PI/ 180 * latA) * 
  sin(PI/ 180 * lngA) * cos(PI/ 180 * latB) * sin(PI/ 180 * lngB) + 
  sin(PI/ 180 * latA) * sin(PI/ 180 * latB))
RC
+1  A: 

There are several algorithms that convert latitude/longitude coordinates to distance in miles.

Refer to: http://www.meridianworlddata.com/Distance-Calculation.asp

I tested all of them, and if you are really worried about performance, you can use:

sqrt(x * x + y * y)

where x = 69.1 * (lat2 - lat1) 
and y = 53.0 * (lon2 - lon1) 

Which is a good enough approximation.

Related: http://stackoverflow.com/questions/3606139/php-mysql-and-geolocation/3606231#3606231

NullUserException
A: 

If all you are worried about is proximity then Manhattan distance may be sufficient.

boolean isProximate ( double latE , double longE )
{
      return ( ( Math . abs  ( latA - latB ) < latE ) && ( Math . abs ( longA - longB ) < longE ) ) ;
}
emory