![](/img/trans.png)
[英]How can i determine if iphones CoreLocation is using satellites or cell tower triangulation to find the current location?
[英]can't find location via Corelocation
我使用corelocation來檢測要在URL中使用的緯度和經度,但是日志中的打印結果均為0.00000
這是我的代碼
mapViewcontroller.m
#import <CoreLocation/CoreLocation.h>
@interface mapsViewController () <CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *mapsweb;
@property(weak,nonatomic) CLLocationManager *locationmanager;
@end
@implementation mapsViewController
-(NSString *)getlat{
return [NSString stringWithFormat:@"%f",_locationmanager.location.coordinate.latitude];
}
-(NSString *)getlon{
return [NSString stringWithFormat:@"%f",_locationmanager.location.coordinate.longitude];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_locationmanager = [[CLLocationManager alloc]init];
_locationmanager.distanceFilter = kCLDistanceFilterNone;
_locationmanager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[_locationmanager startUpdatingLocation];
NSString *t1 = @"http://mymaps.com/clat/";
NSString *la = [self getlat];
NSString *t2 = @"/clng/";
NSString *lo = [self getlon];
NSLog(@"latitude is %@",[self getlat]);
NSLog(@"Longitude is %@",[self getlon]);
您沒有使用requestWhenInUseAuthorization或requestAlwaysAuthorization
還請與以下代表核實-
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
}
您是否在Info.plist中添加了NSLocationWhenInUseUsageDescription? 如果不是,則添加此屬性並將其類型設置為String,值= requestWhenInUseAuthorization
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.