gpt4 book ai didi

ios - 以编程方式插入纬度和经度以进行反向地理定位

转载 作者:行者123 更新时间:2023-11-29 03:52:03 30 4
gpt4 key购买 nike

我有一种情况,我从 XML 文件中提取纬度和经度,解析并显示它。并且我成功地能够在两个不同的 UILabels 中执行此操作。但现在我需要位置并显示它有人可以建议我如何实现这一点吗?我有这段代码,但它只能让我从模拟器中选择坐标值。

- (IBAction)geoCodeLocation:(id)sender{

//Geocoding Block
[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {



//Get nearby address
CLPlacemark *placemark = [placemarks objectAtIndex:0];

//String to hold address
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];

//Print the location to console
NSLog(@"I am currently at %@",locatedAt);

//Set the label text to current location
[locationLabel setText:locatedAt];

}];
}

建议:这个问题与 XML 解析无关。

最佳答案

试试这个

 CLLocation *location = [[CLLocation alloc] initWithLatitude:37.78583400      longitude:-122.40641700];

[self.geoCoder reverseGeocodeLocation: location completionHandler:
^(NSArray *placemarks, NSError *error) {

//Get nearby address
CLPlacemark *placemark = [placemarks objectAtIndex:0];

//String to hold address
locatedAtcountry = placemark.country;
locatedAtcity = placemark.locality;
locatedAtisocountry = placemark.ISOcountryCode;

//Print the location to console
NSLog(@"Estas en %@",locatedAtcountry);
NSLog(@"Estas en %@",locatedAtcity);
NSLog(@"Estas en %@",locatedAtisocountry);

[cityLabel setText:[NSString stringWithFormat:@"%@",locatedAtcity]];
[locationLabel setText:[NSString stringWithFormat:@"%@",locatedAtcountry]];

//Set the label text to current location
//[locationLabel setText:locatedAt];

}];

关于ios - 以编程方式插入纬度和经度以进行反向地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16975319/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com