3

when i change the latitude and longitude value of another location my app closes automatically help ?

if (1)
{
    CLLocationCoordinate2D cordi;
    cordi.latitude  =  45.574779;
    cordi.longitude = -122.685366;

    MKReverseGeocoder *coder = [[MKReverseGeocoder alloc] initWithCoordinate:cordi];
    coder.delegate = self;
    [coder start];
}
else
{
    [self performSelectorInBackground:@selector(showWeather:) withObject:@"97217"];
}
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
N15H4NJ0
  • 33
  • 3
  • 1
    Do you get an error message or stack trace in the console? Look at Apple's sample app [CurrentAddress](http://developer.apple.com/library/ios/#samplecode/CurrentAddress/Introduction/Intro.html) to see how they declare, create and use MKReverseGeocoder. –  Apr 07 '11 at 18:38
  • 1
    Have you defined methods for both reverseGeocoder:didFailWithError: and reverseGeocoder:didFindPlacemark:? – Twelve47 Apr 07 '11 at 19:16

1 Answers1

1

As Twelve47 Said, you should fully implement the delegate, since both methods are not optional.

It sounds like you have only implemented the sucess method:

– reverseGeocoder:didFindPlacemark:

so when you change the location to somewhere than cant be geocoded, the fail methods gets called which causes a error.

Add this code:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
   NSLog(@"Geocoder failed with error: %@",error);
}
Robert
  • 37,670
  • 37
  • 171
  • 213