我想要我设备的当前纬度和经度。当我的程序第一次定位设备时,我可以打印纬度和经度,但我无法刷新它。
-(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/