LKM*_*LKM 4 gps objective-c ios
我试着获得我所在位置的坐标.
我stackoverflowed所以我编码如下:
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);
Run Code Online (Sandbox Code Playgroud)
但我总是一直都是0.上面的代码是错的吗?或者我没有为GPS定位设置我的模拟器?
我不明白为什么我在协调方面遇到麻烦.
首先,您的代码中存在以下几个问题:
-locationManager:didUpdateLocations:和-locationManager:didFailWithError:委派方法[locationMamager requestWhenInUseAuthorization];或[locationMamager requestAlwaysAuthorization];NSLocationWhenInUseUsageDescription或NSLocationAlwaysUsageDescription相应地您可以使用Xcode模拟位置,查看来自Apple的信息:https://developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/simulating_locations.html