6

I have a place's table, in this, each record has latitude and longitude of that place.

Now I want to find nearby places (within 10 KM) from places table according to given lat-long.

I have 500 + place's records in my database table.

Currently i am using mysql query for the same :

 SELECT FROM provider_venues WHERE IFNULL( ( 111.111 (
 DEGREES(ACOS(COS(RADIANS(26.2743661)) COS(RADIANS(venue_lat))
 COS(RADIANS(73.02130979999993 - venue_long)) +
 SIN(RADIANS(26.2743661)) * SIN(RADIANS(venue_lat))))) ), 0) <= 10

But distance i the am getting from above query is different from the distance i am getting from google API.

I can use google API for this but using google API for every record may not be good approach.

Is there any way to use google API in more optimized way or any other solution to get the expected result faster?

dpapadopoulos
  • 1,834
  • 5
  • 23
  • 34
  • 2
    Aren't you supposed to have the radius of the earth in there somewhere? (6371 * ...) – Strawberry Feb 25 '19 at 07:24
  • If you use a rectangle criteria for the given lat-long you'll restrict the set on which you apply all these trigonometric functions on. – danblack Feb 25 '19 at 07:30
  • If you have only have 500 records there and it's not going to grow much you can put it all in let's say memcache and each time you need you can calculate trigonometrically distances to your desired location from each location, then sort and get your top nearby places – Taggart Comet Oct 17 '20 at 07:29

0 Answers0