代码应该进行地址搜索。第CLLocationCoordinate2D location2 = [self adressLocation
行无效。它说的是“无效的初始化程序”。可能有什么不对?
-(IBAction) search {
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.4;
span.longitudeDelta = 0.4;
CLLocationCoordinate2D location2 = [self adressLocation];
region.span = span;
region.center = location2;
Mark adr = [[Mark alloc] initWithCoordinate:location2];
[mapView addAnnotation:adr];
}
-(CLLocationCoordinate2D) adressLocation {
NSString * urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[suchFeld.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString * locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:&fileError];
NSArray * listItems = [locationString componentsSeparatedByString:@","];
double latitude2 = 0.0;
double longitude2 = 0.0;
if ([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"])
{
latitude2 = [[listItems objectAtIndex:2] doubleValue];
longitude2 = [[listItems objectAtIndex:3] doubleValue];
} else {
// error
CLLocationCoordinate2D location2;
location2.latitude = latitude2;
location2.longitude = longitude2;
return location2;
}
答案 0 :(得分:0)
adressLocation
方法可能未在.h文件中声明,并且由于该方法是在调用它的代码之后定义的,因此编译器会给出该错误。将其添加到.h文件中:
-(CLLocationCoordinate2D) adressLocation;
一些单独的问题:
在search
方法中,您有Mark adr = [[Mark alloc]...
这应该是Mark *adr = [[Mark alloc]...
(注意星号)。
同样在search
方法中,您需要在[adr release];
行之后执行addAnnotation
。
最后,adressLocation
在所有情况下都不会返回值
它只在else部分中执行return
。它还需要在if-part中返回一个值。