Objective c 目标C:获得';无效的初始值设定项错误';设置CLLocationCoordinate2D位置时

Objective c 目标C:获得';无效的初始值设定项错误';设置CLLocationCoordinate2D位置时,objective-c,ios,cllocation,Objective C,Ios,Cllocation,我正试图找到并设置如下所示的位置,但我不断收到错误“无效初始值设定项” CLLocationCoordinate2D location =[self.mapView addressLocation]; 其中addressLocation方法如下所示 -(CLLocationCoordinate2D) addressLocation { NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/ma

我正试图找到并设置如下所示的位置,但我不断收到错误“无效初始值设定项”

CLLocationCoordinate2D location =[self.mapView addressLocation];
其中addressLocation方法如下所示

-(CLLocationCoordinate2D) addressLocation {
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                       [searchBar.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    //NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
    NSError* error;
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
    NSArray *listItems = [locationString componentsSeparatedByString:@","];

    double latitude = 0.0;
    double longitude = 0.0;

    if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
        latitude = [[listItems objectAtIndex:2] doubleValue];
        longitude = [[listItems objectAtIndex:3] doubleValue];
    }
    else {
        //Show error
    }
    CLLocationCoordinate2D location;
    location.latitude = latitude;
    location.longitude = longitude;

    return location;
}

您能告诉我为什么会出现“无效初始值设定项”错误吗?我已经导入了corelocation框架,还导入了头文件。所以不确定是什么问题。

您正在调用
[self.mapView addressLocation]
。它不应该是
[self addressLocation]
?我假设
mapView
是你班上的
MKMapView
,没有任何
addressLocation
方法。

我尝试使用[self-addressLocation],但仍然得到相同的错误“无效初始值设定项”……这是一个愚蠢的问题,但是你在构建项目时在作业行上得到任何警告吗?您是否在定义addressLocation函数的同一类中赋值?@Gary,我没有收到警告,它在赋值行“无效初始值设定项”上给了我一个错误。此外,addressLocation函数位于我尝试分配位置的同一类中。addressLocation函数是否在.h文件中声明?@Gary,是的,您中了大奖。我太粗心了,没有把它包含在头文件中。添加了它,它现在正在工作。谢谢