我實際上使用核心位置以及地圖工具包框架來獲取按鈕點擊時的用戶位置。我有兩個視圖控制器。第一個是一個普通的視圖控制器,其中包含地圖視圖以及在其中完成的所有核心位置處理以及反向地理編碼。 第二個是表格視圖控制器,顯示從地理編碼和位置的經緯度獲得的數據。將數據傳遞到目標視圖控制器
我得到的問題是我無法將當前位置的信息傳遞給下一個視圖。但是,我可以傳遞我的地理編碼值。這對我來說似乎很奇怪,任何幫助都會令我非常感激。
mapViewController.m
#import "mapViewController.h"
@interface mapViewController()
{
CLLocationManager *locationManager;
CLGeocoder *geoCoder;
CLPlacemark *placemark;
addressViewController *view;
}
@end
@implementation mapViewController
@synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
locationManager = [[CLLocationManager alloc]init];
geoCoder = [[CLGeocoder alloc]init];
self.addressOutlet.enabled = NO;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"addressSegue"])
{
view= segue.destinationViewController;
// assigning the addressPlacemark the same value as the current placemark
view.addressPlacemark = placemark;
NSLog(@"this is perfectly executed");
}
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 600, 600);
[self.mapView setRegion:region animated:YES];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newOne = [locations lastObject];
[locationManager stopUpdatingLocation];
NSLog(@"the new location is : %@", newOne);
NSLog(@"the latitude is %f", newOne.coordinate.latitude);
NSLog(@"the speed is %.2f mps", newOne.speed);
NSLog(@"at time : %@",newOne.timestamp);
//These 4 NSLog statements are returning the outputs as expected
[geoCoder reverseGeocodeLocation:newOne completionHandler:^(NSArray *placemarks, NSError *error) {
placemark = [placemarks objectAtIndex:0];
NSLog(@"the current city is %@",placemark.locality);
self.addressOutlet.enabled = YES;
// view.currentLocation = [[CLLocation alloc]init];
view.currentLocation = newOne; // assigning currentLocation the same location as the newOne
NSLog(@"the currentLocation object has the location : \n %@",view.currentLocation);
//problem : the output of this NSLog gives Null
}];
}
您已經嘗試了什麼?有這麼多問題。去谷歌上查詢! – brianLikeApple 2013-04-10 13:37:38
'Xcode'標籤只應用於有關Xcode工具本身的問題,而不是針對使用Xcode的編程問題。 – 2013-04-10 13:52:59