0

I have an application working on iOS devices getting constantly the current latitude and longitude from the device. I would like to show an alert when the user reaches a certain lon/lat.

Here is the long to be reached : 2.39364456 Here is the lat to be reached : 48.84185814

When the user reaches this point, he should get an alert.

Unfortunately it doesn't work since the user doesn't always get to this exact point.

What I would like to do is : if you are NEAR to this point, in a certain range defined, then we pop up the alert.

I have no idea how to do this. I tried to implement long/lat to UTM converter and then try to work with UTM format but it was a failure.

Is it possible to work with the lon/lat's numbers which are after the comas to make a "range" to be in so the pop up shows ?

Thanks for reading and thanks in advance for your help ;)

  • 1
    p.s. why are you trying to get to a [point off the coast of Somalia](https://www.google.com/maps/place/2%C2%B023'37.1%22N+48%C2%B050'30.7%22E/@2.3936446,48.8418581,7z/data=!3m1!4b1!4m2!3m1!1s0x0:0x0)? – Michael Dautermann May 03 '14 at 11:09
  • Yes, assuming you meant a location in France, the _latitude_ should be +48.nnn and the _longitude_ should be +2.nnn. –  May 03 '14 at 11:24
  • Lol michael Dautermann, I suddenly inverted lon and lat. I now edited the post. So as you can see it is in France, Paris. –  May 03 '14 at 12:14

3 Answers3

2

Sounds like you are looking for the region monitoring functionality that comes in Core Location in iOS.

Here is a related question that talks about that.

And here is some Apple sample code.

And the latest Apple documentation that talks about Region Monitoring.

When your app gets into the region you're watching, your app gets called with the CLLocationManager delegate "locationManager:didEnterRegion:" method. And that is where you can fire your UIAlert from.

Community
  • 1
  • 1
Michael Dautermann
  • 86,557
  • 17
  • 155
  • 196
  • Thanks a lot for your answer. It really helped, I will perhaps use it later to optimize my code. –  May 03 '14 at 12:10
0

You have 2 locations, aCLLocationA which is position defined by you, and aCLLocationB user location which get's updated. Now what you do:

Step 1

Find the distance by using this code between points on Map:

CLLocationDistance distance = [aCLLocationA distanceFromLocation:aCLLocationB];

Step 2

if(distance<=yourRange)
{
    //You have to show popup, because your location is in range with that point
}
E-Riddie
  • 14,052
  • 7
  • 47
  • 70
0
        - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        NSLog(@"didUpdateToLocation: %@", newLocation);
        CLLocation *currentLocation = newLocation;

        if (currentLocation != nil) {
       CLLocation *locA = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];

        }
            CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
            distance = [locA distanceFromLocation:locB];
      if(distance<yourDesiredDiustance)
      {
       show Alert
      }

}

Deep Gami
  • 468
  • 3
  • 13