search

Home  >  Q&A  >  body text

ios - 想问一下商城按距离排序的实现思路

rt,我想实现我们商城的按距离排序,但是后台也没给实现,想问一下怎么实现附近商城的按距离排序呢

高洛峰高洛峰2889 days ago394

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-18 09:09:55

    What does it mean to sort shopping malls by distance? Distance to where? I think you should describe the problem clearly before asking a question.

    Let me guess your usage scenario: there are many malls in your application, scattered in different locations (with the latitude and longitude data of each mall). Now a user comes, and you need to provide this user with a list of malls, sorted by distance. Sorting of users by distance.

    In this case, if the amount of data is relatively small, you can use the distanceFromLocation method of CLLocation to calculate the distance between each mall and the current user's location, and then sort it.

    In addition, it is recommended that the backend handles such needs. Here, I solemnly introduce to you the Geo module of Redis: http://redis.io/commands/georadius. You can geoadd all shopping mall locations into redis. You need You can use georadius to get a list sorted by distance.

    reply
    0
  • Cancelreply