黄舟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.