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

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方法。

关于objective-c - objective-c :设置CLLocationCoordinate2D位置时出现“无效的初始化错误”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5932117/

10-09 07:39