The code should do an adress search. The line CLLocationCoordinate2D location2 = [self adressLocation
isn't working. It's saying "Invalid Initializer". What could be wrong?
-(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 && [[lis开发者_JAVA技巧tItems 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;
}
The adressLocation
method is probably not declared in the .h file and since the method is defined after the code calling it, the compiler gives that error. Add this to the .h file:
-(CLLocationCoordinate2D) adressLocation;
Some separate issues:
In the search
method, you have Mark adr = [[Mark alloc]...
.
This should be Mark *adr = [[Mark alloc]...
(note asterisk).
Also in the search
method, you need to do [adr release];
after the addAnnotation
line.
Finally, adressLocation
does not return a value in all cases.
It only does a return
in the else-part. It needs to return a value in the if-part also.
精彩评论