IPhone MKMapView: detect closest locations in an array from current location

I have an array with approximately 1000 objects, each of which has an exact coordinate value. What I would like to do is take the "Search" button that I have, and, when clicked, determine the current location and calculate the 10 nearest objects in this place. Any tips on a better way? Thank.

+3
source share
2 answers

This formula only works for flat surfaces where the meshes in each direction are the same. This is true on a small scale at the equator, but the further you get from the equator to the lines of longitude, the closer you are to each other, and the latitudinal lines are still at the same distance from each other.

For example, from Auckland, one degree of latitude is ~ 111.2 km, and one longitude is 88.8 km. So the grid is not square. Effectively means that from (0,0) it is further (0,1) than (1,0).

The correct solution is to use Apple CLLocation and its getDistanceFrom: (or distanceFromLocation :), which calculates the true distances based on the surface of the sphere (given the projection WGS84, I think).

+10
source

Mark

, . , , - . .

:

( (x1 - x2)^2 + (y1 - y2)^2 ) ^ (1/2)

, NSMutableArray, , push-pop , 10.

, .

+1

Source: https://habr.com/ru/post/1774278/


All Articles