iOS如何获取实时经纬度

标签 ios objective-c geolocation

我想要我设备的当前纬度和经度。当我的程序第一次定位设备时,我可以打印纬度和经度,但我无法刷新它。

-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    int lastindex = [locations count]-1;

    CLLocation * currentLocation = [locations objectAtIndex:lastindex];

    float latitude =currentLocation.coordinate.latitude;

    float longitude =currentLocation.coordinate.longitude;

    NSLog(@"LAT:%f LONG:%f",latitude,longitude);

    [self latitudeLabel].text = [[NSString alloc]initWithFormat:@"latitude : %@",[[NSNumber numberWithFloat:latitude] stringValue]];

    [self longitudeLabel].text = [[NSString alloc]initWithFormat:@"longitude : %@",[[NSNumber numberWithFloat:longitude] stringValue]];

}

这是我尝试过的方法,但纬度/经度从未更新过。我尝试使用 didUpdateHeading 函数进行尝试,但它也不起作用。

我该怎么做。任何人都可以帮助我解决这个问题。 谢谢你

最佳答案

此方法由 startUpdatingLocation 触发,我假设您正在使用它,因为它至少被调用了一次。每次位置数据更改时都会调用该方法。您的位置是否真的发生了足以触发它的变化?此外,检查 CLLocationManager 上的 distanceFilter 属性并确保它足够低。

关于iOS如何获取实时经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24681255/

相关文章:

ios - 克隆 UIImage 对象时 UIImage 文件太多

ios - 准备从不显示索引项的 Collection View 单元格中继续

javascript - 未捕获的类型错误 : Illegal invocation in Javascript (geolocation)

ios - 通过 NSFetchedResultsController 按距离排序的核心数据中的位置?

android - 如何为 Google map 替换或删除我的位置蓝点周围的圆圈

ios - 如何使用Core Graphics翻转曲线拟合文本?

ios - 如何在 iOS 7.1 中使用 NSURLSession 对 HTTP 请求和响应进行单元测试?

ios - UIImage initWithData : blocking UI thread from async dispatch?

iphone - 在for循环中取消NSOperation?

ios - Xcode AVAudioPlayer 未播放