0
我试图找到并设置位置时,遇到了“无效的初始化程序错误”,但我不断收到错误“无效的初始化程序”目标C:设置如下图所示CLLocationCoordinate2D位置
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 addressLocation],但仍然得到相同的错误'无效的初始化程序'... – Zhen 2011-05-09 04:02:17
这是一个愚蠢的问题,但是当你建立你的项目时,你是否在任务上得到任何警告?你是否在定义addressLocation函数的同一类中进行赋值? – Gary 2011-05-09 04:40:57
@Gary,我没有收到警告,它在赋值行'Invalid Initializer'上给了我一个错误。此外,addressLocation函数位于我尝试分配位置的同一个类中。 – Zhen 2011-05-09 04:46:06