【发布时间】:2014-08-15 09:33:12
【问题描述】:
我正在使用有效的反向地理编码,但我正在尝试分离属性。例如,我想在它自己的文本字段中显示邮政编码。
这是我尝试过的,但我在 if([placemarks count] >0) 处得到一个断点
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// Make sure this is a recent location event
CLLocation *newLocation = [locations lastObject];
NSTimeInterval eventInterval = [newLocation.timestamp timeIntervalSinceNow];
if(abs(eventInterval) < 30.0)
{
// Make sure the event is valid
if (newLocation.horizontalAccuracy < 0)
return;
// Instantiate _geoCoder if it has not been already
if (_geocoder == nil)
_geocoder = [[CLGeocoder alloc] init];
//Only one geocoding instance per action
//so stop any previous geocoding actions before starting this one
if([_geocoder isGeocoding])
[_geocoder cancelGeocode];
[_geocoder reverseGeocodeLocation: newLocation
completionHandler: ^(NSArray* placemarks, NSError* error)
{
if([placemarks count] > 0)
{
CLPlacemark *foundPlacemark = [placemarks objectAtIndex:0];
self.address.text =
[NSString stringWithFormat:@"%@",
foundPlacemark.description];
self.zip.text =
[NSString stringWithFormat:@"%@",
foundPlacemark.postalCode];
}
else if (error.code == kCLErrorGeocodeCanceled)
{
NSLog(@"Geocoding cancelled");
}
else if (error.code == kCLErrorGeocodeFoundNoResult)
{
self.address.text=@"No geocode result found";
}
else if (error.code == kCLErrorGeocodeFoundPartialResult)
{
self.address.text=@"Partial geocode result";
}
else
{
self.address.text =
[NSString stringWithFormat:@"Unknown error: %@",
error.description];
}
}
];
【问题讨论】:
标签: ios objective-c uitextfield geocoding reverse-geocoding