ahhh within a certain distance shouldn't be too much of a problem. Well, i don't know how you're storing your data, but here is what i implimented for my stuff. It's a compiled C mySQL User Defined Function (should be able to add it to any newer version of mySQL) but here is the code:

Code:

#ifdef STANDARD
#include <stdio.h>
#include <string.h>
#ifdef __WIN__
typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
typedef __int64 longlong;
#else
typedef unsigned long long ulonglong;
typedef long long longlong;
#endif /*__WIN__*/
#else
#include <my_global.h>
#include <my_sys.h>
#endif
#include <mysql.h>
#include <m_ctype.h>
#include <m_string.h> // To get strmov()
#ifdef HAVE_DLOPEN
/* These must be right or mysqld will not find the symbol! */
extern "C" {
my_bool geodist_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
void geodist_deinit(UDF_INIT *initid);
double geodist(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error);
}
double pi = 3.141592653589792907377;
double rad(double gr) {return pi * gr / 180.0;}
/*
Simple example of how to get a sequences starting from the first argument
or 1 if no arguments have been given
*/
my_bool geodist_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
if (args->arg_count != 4)
{
strmov(message,"geodis takes 4 args");
return 1;
}
if( args->arg_type[0] != REAL_RESULT || args->arg_type[1] != REAL_RESULT ||
args->arg_type[2] != REAL_RESULT || args->arg_type[3] != REAL_RESULT )
{
strcpy(message, "geodist() requires all 4 parameters to be type REAL");
return 1;
}
// set max decimals to 2 because we are returning miles
initid->decimals = 2;
return 0;
}
void geodist_deinit(UDF_INIT *initid)
{
}
double geodist(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
char *error)
{
double lat1 = 0.0;
double lon1 = 0.0;
double lat2 = 0.0;
double lon2 = 0.0;
lat1 = *((double*) args->args[0]);
lon1 = *((double*)args->args[1]);
lat2 = *((double*)args->args[2]);
lon2 = *((double*)args->args[3]);
return 0.621 * 6371.2 * 2 *
atan2( sqrt(fabs(0 + pow(sin(rad(lat2)/2 - rad(lat1)/2),2) +
cos(rad(lat1)) * cos(rad(lat2)) * pow(sin(rad(lon2)/2 -
rad(lon1)/2),2))),sqrt(fabs(1 - pow(sin(rad(lat2)/2 -
rad(lat1)/2),2) + cos(rad(lat1)) * cos(rad(lat2)) *
pow(sin(rad(lon2)/2 - rad(lon1)/2),2))));
}
#endif /* HAVE_DLOPEN */

I actually had a lot of fun figuring this stuff out..

easiest way to compile is "gcc -shared -o geodist.so -I /usr/local/mysql/include geodist.cpp"

that will create your .so then copy it to /usr/lib or somewhere that mysql knows about and to add, just make sure you have permissions to write to the mysql database and run this:

Code:

create function geodist returns real soname "geodist.so";

Then you can run the function just like any other function. "Select geodist(1.0,2.0,3.0,4.0);" This function takes 4 arguments.. basically 2 pairs of lat/long's and will compute the distance between them (in miles)