How can I search based on distance with the Google Maps API?

  • So, the problem ... I have a field where users can enter their address (which will be GeoCoded through the Google Maps API).
  • I have several widget addresses in my database (saved as an address .. again you can easily geocode).

I need the user to enter their address and a list of my widgets based on the distance from their address. I have THOUSAND addresses for my widgets, and users have an infinite number of addresses.

Any ideas?

Thank.

+3
source share
4 answers
SELECT latitude, longitude, SQRT( POW( 69.1 * ( latitude - 52.58 ) , 2 ) + 
POW( 69.1 * ( - 1.12 - longitude ) * COS( latitude / 57.3 ) , 2 ) ) AS distance 
FROM location ORDER BY distance

- , .

+2

MySQL, ,

+2

Google . , . , .

, :

A/As , , , . . Google, "", . ( - .)

B/ Google , , , 5000 IP- , . , .

C/ , .

D/ .

+1
0
source

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


All Articles