Reputation: 3127
How to create Latitude-Longitude bounds in iPhone using two NE and SW latitude longitude coordinates and I want to check whether my current latitude longitude is in within my latitude longitude bound.
I created a bound using following latitude longitude coordinates:
double minLng = 7.880571
double maxLng = 8.357336
double minLat = 49.108775
double maxLat = 49.288638
I want to check my other latitude longitude is within this bound or not.
Upvotes: 0
Views: 948
Reputation: 5955
Try like this,
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if(newLocation.coordinate.latitude>=49.108775 && newLocation.coordinate.latitude<=49.288638 && newLocation.coordinate.longitude>=7.880571 && newLocation.coordinate.longitude<=8.357336 ) {
// It is in the bounds
}
}
Upvotes: 1
Reputation: 4552
If by current you mean the device's current location, you need to look into the CLLocationManager class and its delegate methods, namely the location
property which contains the information about current latitude and longitude. The rest is pretty straightforward.
Upvotes: 0