我正在尝试显示用户在某些文本字段中输入的地址的纬度和经度值。理想情况下,我希望用户输入地址,然后单击一个按钮,该按钮将找到纬度/经度并将这些值输入到同一 View 中的两个文本字段中。我只是不确定如何在代码中调用这些文本字段的地址值。
这是我到目前为止所拥有的
-(IBAction)getLatLon:(id)sender{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
NSString *addressString = @"%@address, city, county, county, postcode";
[geocoder geocodeAddressString:addressString inRegion:nil completionHandler:^(NSArray* placemarks, NSError* error)
{
for (CLPlacemark * aPlacemark in placemarks)
{ // Process the placemark.
NSLog(@"Got Placemark : %@", aPlacemark);
}
}];
当我硬编码一个值时,它会起作用,例如
NSString *addressString = @"Belfast";
我知道我可能试图将这些值称为错误的值,但在这个阶段我的头脑完全崩溃了!
我的文本字段是这样命名的
addressText.text
cityText.text
countyText.text
countryText.text
postcodeText.text
最佳答案
您需要使用stringWithFormat:方法。在字符串 (%@) 中为要使用的每个字符串添加占位符,然后列出后面的参数(您熟悉 printf
吗?)
关于objective-c - 从文本字段获取值以传递给 CLGeocoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10678577/