Ok thanks that's the answer i was looking for, if you notice in the SQL up above not in the code the parameters are missing and since I am not using PHP I didn't bother looking at the php code. So part article problem, part my problem. I would consider changing the SQL statement above the PHP code to indicate where the parameters are.
On Mar 4, 1:16 pm, Barry Hunter <[email protected]> wrote: > Not sure if you looking at the same sql, but this: > > SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * > cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( > radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 > ORDER BY distance LIMIT 0 , 20; > > only returns the 20 closest results, that are within the specificed > distance (25 miles) > It also returns the distance itself in the results. > > The parametered query is there in the PHP code > > // 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); > > On 04/03/2009, [email protected] <[email protected]> wrote: > > > > > > > I know there have been many posts about this in the past, however the > > sql provided in the article is not correct. I was hoping someone > > could shed some light. the problem is that the sql statement is > > lacking the necessary input parameters to use to calculate the actual > > distance as it is right now all records in the database will be > > returned because the query takes no input and uses the stores lat and > > long to calculate the distance only. Does anyone know which of the > > lats and lngs in the query need to be replaced with the input lat and > > long from the location of the person doing the search? > > > Here is the article > > http://code.google.com/apis/maps/articles/phpsqlsearch.html > > -- > Barry > > -www.nearby.org.uk-www.geograph.org.uk- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---
