-1

I have a MapView with user location, and a bunch of Map annotations.

At first I want to show all the possible pins on the map. (succeeded in doing that)

Then I want to zoom in the map to show only the annotations that are within 50 KMs away from the userLocation annotation

How do i find these annotations?

Lena Bru
  • 13,521
  • 11
  • 61
  • 126
  • You don't. You filter the information that you are using to create the annotations. Explain what that information is and why you're using 50Km instead of the map zoom (so bounding map rect). – Wain Jul 14 '14 at 12:03
  • hi @lena Bru i think this link helpful to you http://stackoverflow.com/questions/21554127/how-to-get-current-location-using-cllocationmanager-in-ios – Ilesh P Jul 14 '14 at 12:31

2 Answers2

0

You have to calculate the distance between pin and userlocation using :

CLLocationDistance dist = [loc1 distanceFromLocation:loc2];

where loc1 and loc2 are CLLocation objects. You have to filter the pins array with this distance parameter.

Ritu
  • 661
  • 3
  • 8
0
- (CLLocation*)closestLocationToLocation:(CLLocation*)currLocation
{
    CLLocationDistance minDistance;

    CLLocation *closestLocation = nil;

    for (CLLocation *location in arrayOfLocations) {
        CLLocationDistance distance = [location distanceFromLocation:currLocation];

        if (distance <= minDistance
            || closestLocation == nil) {
            minDistance = distance;
            closestLocation = location;
        }
    }

    //closestLocation is now the location from your array which is closest to the current location or nil if there are no locations in your array.

    return closestLocation;

}

I think Its May be Very Helpful to You.Thanks!!

Ilesh P
  • 3,940
  • 1
  • 24
  • 49