【问题标题】:Get attitude and longitude without using the map不使用地图获取经纬度
【发布时间】:2015-01-27 23:23:39
【问题描述】:

我想在不使用地图的情况下获取当前位置的纬度和经度,是否可以这样,我在网上搜索没有得到,谁能帮我找到。

我尝试使用核心位置进行此操作,但即使我一无所获。 请告诉我如何找到经纬度,谢谢。

//remember to stop before you are done, either here or in view disappearance.

- (void) dealloc
{   [locationManager stopUpdatingLocation];  } 

【问题讨论】:

    标签: ios iphone google-maps map ios8


    【解决方案1】:

    在 .h 文件中:

    CLLocationManager *locationMgr;
    

    在 .m 文件中:加载时

      locationMgr =[[CLLocationManager alloc] init];
    locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
    locationMgr.delegate = self;
    if ([locationMgr respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [locationMgr requestWhenInUseAuthorization];
    }
    [locationMgr startUpdatingLocation];
    

    添加以下代表:

    -(void)locationManager:(CLLocationManager *)manager
       didUpdateToLocation:(CLLocation *)newLocation
              fromLocation:(CLLocation *)oldLocation
    {
        // Handle location updates
        CLLocationCoordinate2D location=newLocation.coordinate;
        float altitude = newLocation.altitude;
    }
    
    -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
    // Handle error
        NSLog(@"error: %@",[error localizedDescription]);
    }
    

    您可能没有授权用户的位置。这就是为什么你什么也得不到 谢谢

    【讨论】:

    • 我如何从这里打印纬度和经度
    • 你的项目中添加了correlation.framework吗?
    • 你添加了但在授权时出现错误,那么如何获得授权
    • if ([locationMgr respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [locationMgr requestWhenInUseAuthorization]; }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    相关资源
    最近更新 更多