目标C:设置CLLocationCoordinate2D位置时出现“无效的初始化程序错误”

时间:2011-05-09 03:13:21

标签: objective-c ios cllocation

我正在尝试查找并设置如下所示的位置,但我一直收到错误'无效的初始化程序'

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;
}

您能否告诉我为什么会收到“初始化程序无效”错误?我已经导入了位置定位框架并导入了头文件。所以不确定是什么问题。

1 个答案:

答案 0 :(得分:2)

您正在调用[self.mapView addressLocation]。不应该是[self addressLocation]吗?我假设mapView是您班级中的MKMapView,并且没有任何addressLocation方法。