I try to get coordinate of my location.
I stackoverflowed so what I coded is below:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
self.longitude=coordinate.longitude;
self.latitude=coordinate.latitude;
NSLog(@"dLongitude : %f",self.longitude);
NSLog(@"dLatitude : %f", self.latitude);
But I'm always getting 0 all the time. Is the code above wrong? or I didn't set my simulator for GPS location?
I don't understand why I'm having trouble in getting coordinate.
Firstly, here are several issues in your code:
-locationManager:didUpdateLocations:
and -locationManager:didFailWithError:
delegate methods[locationMamager requestWhenInUseAuthorization];
or [locationMamager requestAlwaysAuthorization];
NSLocationWhenInUseUsageDescription
or NSLocationAlwaysUsageDescription
accordingly in your Info.plistYou can simulate location using Xcode, look at the information from Apple: https://developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/simulating_locations.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With