Get the shortest distance from a point

前端 未结 8 571
长发绾君心
长发绾君心 2021-01-01 06:36

I have this table in sqlite

Locations
ID
Lat ( latitude)
Lon ( longitude) 
Type
Name
City

I have for example 100 records what I need is to

相关标签:
8条回答
  • 2021-01-01 07:15

    Though this is not a best option.
    Let you are trying to figure out shortest distance within N mile/km radious for fixed no of locations/your location table data are not changing regularly.
    Add another column Distance_Index (DI) a self multi reference key ArrayType. Once run a procedure and update the DI with ID in ascending order accoording to distance from this DI. Now from next time onwords distance is with you. just make a query to the database and use it.
    Sample table data

    Now, in your problem no of location are less within N, then DI will not be too much long.Just as an opinion.

    0 讨论(0)
  • 2021-01-01 07:17

    Distance between two points: ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ 0.5. However, distance between these points are straight lines. Most likely, there are variables like local vs highway, not to mention one-way streets and waterways, where you need to find the nearest bridge. Therefore, I suggest using Google and Bing maps api. The are free for a limited number of searches.

    0 讨论(0)
提交回复
热议问题