I want to check the user device location is in India or not and, if location is not India then user can't able to use the app, I did it using region setting but I want to do it using GeoLocation???
Asked
Active
Viewed 151 times
1 Answers
2
Objective-C
CLLocation *location = [[CLLocation alloc]
initWithLatitude:+38.4112810
longitude:-122.8409780f];
CLGeocoder*myGeocoder = [[CLGeocoder alloc] init];
[myGeocoder
reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && placemarks.count > 0){
CLPlacemark *placemark = placemarks[0];
NSLog(@"Country = %@", placemark.country);
NSLog(@"Postal Code = %@", placemark.postalCode);
NSLog(@"Locality = %@", placemark.locality);
}
else if (error == nil && placemarks.count == 0){
NSLog(@"No results were returned.");
}
else if (error != nil) {
NSLog(@"An error occurred = %@", error);
}
}];
Swift
func gecode(location:CLLocation)
{
let geoCoder = CLGeocoder()
geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
if(error != nil)
{
return
}
if let placeMark = placemarks?[0] {
if let country = placeMark.addressDictionary!["Country"] as? String {
if country == "India" {
//
}
}
}
})
}

Shehata Gamal
- 98,760
- 8
- 65
- 87
-
I am not well aware of swift can you please explain it in objective c. – MahajanSagar May 07 '18 at 12:46
-
see edit ......... – Shehata Gamal May 07 '18 at 13:06
-
Can plzz help . . . I need to ask user for location permission but if he dont allow then i wanted to call method how can i do it?? – MahajanSagar May 09 '18 at 10:20