I'm an app on iOS, which has Trip Planner. For example I'm using google direction API to get route from New York to Boston. I have 50 different latitude longitude to make polylines on the map. After that I need to get places on this route which I can visit on the way to Boston.
Google directions API gives me:
latitude = "30.308399"; longitude = "-89.748299";
latitude = "30.310930"; longitude = "-89.818604";
latitude = "30.350050"; longitude = "-89.916054";
latitude = "30.432850"; longitude = "-90.098549";
....
Right now for each point I do search in mysql database to get closest places:
select id,title,type_id,service_id,latitude,longitude,state,city,zip,address, ( 3959 * acos( cos( radians(31.72723) ) * cos( radians(latitude ) ) * cos( radians( longitude ) - radians(-106.3047)) + sin( radians(31.72723) ) * sin( radians(latitude ) ) ) ) AS distance from places distance <= 10 order by distance ASC limit 10
But if this trip from New York to San Francisco, I will have 800 points, I would to make 800 query to database which takes more than 2 seconds in total. And I have 7 different tables, it would be 14 seconds.
What is the best to do if?