Finding Locations with MySQL - Google maps

To search by kilometers instead of miles, replace 3959 with 6371.To find locations in your markers table that are within a certain radius distance of a given latitude/longitude, you can use a SELECT statement based on the Haversine formula.Mathemetical explanation is given by Wikipedia.

To search by kilometers instead of miles, replace 3959 with 6371.

// Search the rows in the markers table$query = sprintf('SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20', mysql_real_escape_string($center_lat), mysql_real_escape_string($center_lng), mysql_real_escape_string($center_lat), mysql_real_escape_string($radius)
);

$result = mysql_query($query);

https://developers.google.com/maps/articles/phpsqlsearch_v3