How can I effectively use multiple length search points

I am an iOS app that has Trip Planner. For example, I am using the google API to get from New York to Boston. I have 50 different latitudes and longitudes to make the polylines on the map. After that I need to get on this route, which I can visit on my way to Boston.

Google 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 am searching the mysql database for the closest locations:

select id, name, type_id, service_id, latitude, longitude, state, city, zip code, address, (3959 * acos (cos (radians (31.72723)) * cos (radians (latitude)) * cos (radians (longitude) - radians (-106.3047)) + sin (sin radians (31.72723)) * sin (radians (latitude)))) AS distance from location distance <= 10 orders of magnitude per distance ASC limit 10

But if this trip from New York to San Francisco, I have 800 points, I would make 800 database queries, which takes more than 2 seconds. And I have 7 different tables, it will be 14 seconds.

What is the best thing to do if?

Example

+3


source to share


3 answers


Here's one way to make it faster:

(1) Place the indices in the table for latitude and longitude.



(2) In the query, first select only those places in the horizontal and vertical distance of a point on the route, close enough to be interesting. Select a range of latitude and longitude.

(3) Then sort these points by distance, inside or outside the query.

+2


source


My best guess is that this is a Voronoi diagram . But this is difficult to implement.



Notes: Since you only have 80k points, you can cache all of these points inside the application and return from required applications.

+1


source


Try entering a minimum distance suggestion where Diatance> 100, etc.

This is called a cone scan. You start at a low resolution and then continue to grow as you get closer.

-1


source







All Articles