How is a 1000ft or 1/2 mile distance determined with mapkit? Either a radius from some pin or the distance between two pins.
For example, I center the map on pin A. Pins B, C, and D are also on the map at various distances from pin A. B and C are within 1/2 mile from A but D is 1 mile away. I’d like to know that B and C are within 1/2 mile from A. How can I calculate that?
Since you’ve stated that the two different points are “pins”, I’m going to assume you’re using MKPinAnnotationView (or some other annotation view). If not, you’re going to have to get the location some other way.
If you have pointers to the annotation objects for these locations, then you can easily call
-coordinateon them, create CLLocations from these coordinates (using-initWithLatitude:longitude:), and then use the method-getDistanceFromto retrieve the distance in meters. From there, it’s an easy conversion to miles. All told, the code would look something like this:You’ll end up with the distance in miles, and can compare it from there. Hope this helps.