Search radius for PHP, MYSQL and Google Maps

Im looking for a database with latitude and longitude locations. I want to get all locations in a specific radius.

Then I encode the returned results in JSON and retrieve the data using ajax, however I get an undefined error meaning there is no data returned from the database.

Can anyone see where I'm wrong?

Here is my request

$sql="SELECT *, ACOS( SIN( RADIANS( `lat` ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( `lat` ) ) * COS( RADIANS( $fLat )) * COS( RADIANS( `lng` ) - RADIANS( $fLon )) ) * 6380 AS `distance` FROM `markers` WHERE ACOS( SIN( RADIANS( `lat` ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( `lat` ) ) * COS( RADIANS( $fLat )) * COS( RADIANS( `lng` ) - RADIANS( $fLon )) ) * 6380 < 10 ORDER BY `distance`"; $result = mysql_query($sql); while($r = mysql_fetch_assoc($result)) $rows[] = $r; echo json_encode($rows); 
+4
source share
2 answers

I don't really help with a trigger or SQL, I just saw enough questions on Google maps to point you to this lesson:

https://developers.google.com/maps/articles/phpsqlsearch#findnearsql

There is a search for spots by distance in a radius, which you can try hoping that it works for you.

Use 3959 (in miles) or 6371 (in km)

+5
source

Try the following:

 $sql="SELECT * , ACOS( SIN( RADIANS( 'lat' ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( 'lat' ) ) * COS( RADIANS( $fLat )) * COS( RADIANS( 'lng' ) - RADIANS( $fLon )) ) * 6380 AS distance FROM 'markers' WHERE distance < 10 ORDER BY distance"; $result = mysql_query($sql); $rows = mysql_fetch_assoc($result)); echo json_encode($rows); ` 
0
source

Source: https://habr.com/ru/post/1413055/


All Articles