Distance between Long Lat coord using SQLITE

后端 未结 2 1278
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 16:05

I\'ve got an sqlite db with long and lat of shops and I want to find out the closest 5 shops.

So the following code works fine.

    if(sqlite3_prepare_v2         


        
相关标签:
2条回答
  • 2021-02-06 16:35

    The fastest way to find nearby locations in SQL is to use the Haversine formula in an SQL query. Do a Google search for sqlite and Haversine and you'll find an implementation.

    Here's one I've used before:

    http://www.thismuchiknow.co.uk/?p=71

    0 讨论(0)
  • 2021-02-06 16:45

    you have to run through every element only once so the complexity is fairly good. you need a kind of fixed size Deque-container, a kind of linked list or a fixed size array, fixed by the size of 5, the number of shops you want to get from every point. add always the shop with the most minimal distance to the Deque. after running through your db you are have the nearest 5 shops in your deque.

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