Passing NSString from one method to another [closed] - iphone

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I've got myself some of a newbie problem.
I got this method to determine the zip code where the iPhone is located, based on GPS coordinates. Reverse Geocoding. My method works, I know this, since it has no problem writing out the correct zip code to a label.
But I need this zip code to be stored in a string that I can use inside a method I use to compose a SMS.
Anyone can help me with that?
Tell me if an source code is necessary! (Just not currently sitting on my work comp)
Clearly i've been misunderstood, should have posted som code.
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"didUpdateToLocation: %#", newLocation);
CLLocation *currentLocation = newLocation;
// Reverse Geocoding
NSLog(#"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(#"Found placemarks: %#, error: %#", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
**postalCode** = [NSString stringWithFormat:#"%#",
placemark.postalCode];
} else {
NSLog(#"%#", error.debugDescription);
}
} ];
}
Here i try to save the zip code inside the NSString named postalCode (highlighted with "**")
I try to load it again in sms composer
-(void)displaySMSComposerSheet
{
CLLocation *currentLocation;
// Reverse Geocoding
NSLog(#"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(#"Found placemarks: %#, error: %#", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
postalCode = [NSString stringWithFormat:#"%#",
placemark.postalCode];
} else {
NSLog(#"%#", error.debugDescription);
}
} ];
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.recipients = [NSArray arrayWithObjects:#"1220", nil];
picker.body = [NSString stringWithFormat:#"Dog %#", (placemark.)postalCode];
picker.messageComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
}
only prints out in the SMS window:
Dog (null)
And i'm sure i have the coordinates, they get printed out in the output.
Hope this helps to understand the question better

#import <CoreLocation/CoreLocation.h>
#interface SomeController : UIViewController <CLLocationManagerDelegate>
#property (strong,nonatomic) CLLocationManager *locationManager;
#end
#implementation SomeController
-(void) trackUpdates
{
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
self.locationManager.distanceFilter = 10.0f;
if ([CLLocationManager locationServicesEnabled]){
[self.locationManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
CLGeocoder* gcrev = [[CLGeocoder alloc] init];
[gcrev reverseGeocodeLocation:[locations lastObject]
completionHandler:^(NSArray *placemarks, NSError *error)
{
CLPlacemark* revMark = [placemarks objectAtIndex:0];
NSString *zip = [revMark.addressDictionary objectForKey:#"ZIP"];
NSLog(#"%#",zip);
// ... do something with the zip, store in an ivar, call a method, etc.
}];
}
-(void)viewDidLoad {
[super viewDidLoad];
[self trackUpdates];
}
#end

Related

Object is being saved before I can set the variable. How do I get around this?

I have view controller that prompts the user to enter in some location information, then click submit. When that happens, the data is thrown into a place dictionary and then geocoded through the methods updatePlaceDictionary and geocode. [userListing saveInBackground] then sends the object to an online database. Here is the submit method, which is called when the user fills in the information and clicks submit, along with the updatePlaceDictionary and geocode methods:
- (void)submit{
PFObject* userListing = [PFObject objectWithClassName:#"userListing"];
[self updatePlaceDictionary];
[self geocode];
[userListing setObject:listingLocation forKey:#"location"];
[userListing saveInBackground];
[listings addObject:userListing];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)updatePlaceDictionary {
[self.placeDictionary setValue:self.streetField.text forKey:#"Street"];
[self.placeDictionary setValue:self.cityField.text forKey:#"City"];
[self.placeDictionary setValue:self.stateField.text forKey:#"State"];
[self.placeDictionary setValue:self.zipField.text forKey:#"ZIP"];
}
- (void)geocode{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressDictionary:self.placeDictionary completionHandler:^(NSArray *placemarks, NSError *error) {
if([placemarks count]) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
listingLocation = [PFGeoPoint geoPointWithLatitude:coordinate.latitude longitude:coordinate.longitude];
} else {
NSLog(#"error");
}
}];
}
All three methods work perfectly fine. The problem is, in the submit method, the line:
[userListing setObject:listingLocation forKey#"location"];
just ends up giving the key "location" a value of (0,0). This is occurring because geocode runs asynchronously, and does not finish by the time the above line is reached. How can I have this value set AFTER geocode is finished running?
You entire code here is going to have to be a little asynchronous. Your geocode method can have a block callback passed in, and call it when you are done with the geocode.
- (void)submit{
PFObject* userListing = [PFObject objectWithClassName:#"userListing"];
[self updatePlaceDictionary];
[self geocode:^{
[userListing setObject:listingLocation forKey:#"location"];
[userListing saveInBackground];
[listings addObject:userListing];
[self.navigationController popViewControllerAnimated:YES];
}];
}
- (void)updatePlaceDictionary {
[self.placeDictionary setValue:self.streetField.text forKey:#"Street"];
[self.placeDictionary setValue:self.cityField.text forKey:#"City"];
[self.placeDictionary setValue:self.stateField.text forKey:#"State"];
[self.placeDictionary setValue:self.zipField.text forKey:#"ZIP"];
}
- (void)geocode:(void (^)(void))callback {
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressDictionary:self.placeDictionary completionHandler:^(NSArray *placemarks, NSError *error) {
if([placemarks count]) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
listingLocation = [PFGeoPoint geoPointWithLatitude:coordinate.latitude longitude:coordinate.longitude];
if (callback) {
callback();
}
} else {
NSLog(#"error");
}
}];
}

CLLocationManager not getting City name

I am trying to get the current city and country using CLLocationManager with below code -
#pragma mark - Core Location Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];
[reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(#"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(#"Geocode failed with error: %#", error);
return;
}
NSLog(#"Received placemarks: %#", placemarks);
CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];
NSString *countryCode = myPlacemark.ISOcountryCode;
NSString *countryName = myPlacemark.country;
NSString *city1 = myPlacemark.subLocality;
NSString *city2 = myPlacemark.locality;
NSLog(#"My country code: %#, countryName: %#, city1: %#, city2: %#", countryCode, countryName, city1, city2);
}];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
CLLocationDirection th=[newHeading trueHeading];
NSLog(#"True Heading value is=%f",th);
CLLocationDirection magnetic=[newHeading magneticHeading];
NSLog(#"Magnetic Heading value is=%f",magnetic);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSString *errorType = (error.code == kCLErrorDenied) ? NSLocalizedString(#"access_denied", #"") : NSLocalizedString(#"unknown_error", #"");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(#"error_getting_location", #"")
message:errorType
delegate:nil
cancelButtonTitle:NSLocalizedString(#"ok", #"")
otherButtonTitles:nil];
[alert show];
}
It always gives the result with -
My country code: IN, countryName: India, city1: (null), city2: (null)
I don't know what may be the issue for this. Has anyone faced this issue that can't able to get the city name using CLLocationManager
EDITED:
- (void) getReverseGeocode
{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
if(currentLatLong.count > 0)
{
CLLocationCoordinate2D myCoOrdinate;
myCoOrdinate.latitude = LatValue;
myCoOrdinate.longitude = LangValue;
CLLocation *location = [[CLLocation alloc] initWithLatitude:myCoOrdinate.latitude longitude:myCoOrdinate.longitude];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if (error)
{
NSLog(#"failed with error: %#", error);
return;
}
if(placemarks.count > 0)
{
NSString *MyAddress = #"";
NSString *city = #"";
if([placemark.addressDictionary objectForKey:#"FormattedAddressLines"] != NULL)
MyAddress = [[placemark.addressDictionary objectForKey:#"FormattedAddressLines"] componentsJoinedByString:#", "];
else
MyAddress = #"Address Not founded";
if([placemark.addressDictionary objectForKey:#"SubAdministrativeArea"] != NULL)
city = [placemark.addressDictionary objectForKey:#"SubAdministrativeArea"];
else if([placemark.addressDictionary objectForKey:#"City"] != NULL)
city = [placemark.addressDictionary objectForKey:#"City"];
else if([placemark.addressDictionary objectForKey:#"Country"] != NULL)
city = [placemark.addressDictionary objectForKey:#"Country"];
else
city = #"City Not founded";
NSLog(#"%#",city);
NSLog(#"%#", MyAddress);
}
}];
}
}
You know about the apple maps and there database for the location, better try with google places api for getting more accurate and detailed information for reverse geocoding. I have tried same for auto filling the place names, but didn't worked,so went using google places api, there is one more free api try geonames.org
in .h file
#import <CoreLocation/CoreLocation.h>
#interface ClassDemo : NSObject<NSXMLParserDelegate,CLLocationManagerDelegate>
{
BOOL got;
BOOL needParser;
NSMutableArray *currentplaceArray;
}
#property (nonatomic, retain) CLLocation *currentLocation;
#property (nonatomic, getter = isResultsLoaded) BOOL resultsLoaded;
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (strong, nonatomic) CLGeocoder *geoCoder;
in .m
#synthesize locationManager,currentLocation;
- (void)viewDidLoad
{
got=NO;
needParser=YES;
currentplaceArray=[[NSMutableArray alloc]init];
//******** Location MAnager Allocation And Intialization********//
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if ([self isResultsLoaded])
{
return;
}
[self setResultsLoaded:YES];
currentLocation = newLocation;
NSLog(#"%#",currentLocation);
NSXMLParser *parser = [[NSXMLParser alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat: #"http://maps.googleapis.com/maps/api/geocode/xml?latlng=%f,%f&sensor=false",newLocation.coordinate.latitude,newLocation.coordinate.longitude]]];
[parser setDelegate:self];
[parser parse];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(#"%#",elementName);
if([elementName isEqualToString:#"formatted_address"])
{
got = YES; //got is a BOOL
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(got&&needParser){
got=NO;
NSLog(#"the address is = %#",string);
NSArray *tempPlaceArray=[string componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#",/"]];
NSLog(#"%#",tempPlaceArray);
for(int i=0; i <[tempPlaceArray count]; i++)
{
NSString *tempString=[[tempPlaceArray objectAtIndex:i]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSLog(#"%#",tempString);
if (![currentplaceArray containsObject:tempString])
{
if ([tempString length]!=0)
{
[currentplaceArray addObject:tempString];
}
}
}
needParser=NO;
TempLocation *obj=[[TempLocation alloc]init];
obj.countryName=[currentplaceArray objectAtIndex:[currentplaceArray count]-1];
obj.stateName=[currentplaceArray objectAtIndex:[currentplaceArray count]-2];
obj.cityName=[currentplaceArray objectAtIndex:[currentplaceArray count]-3];
obj.fullAdd=string;
[[Database getDBObject]insertIntoCurrentLocationTable:obj.cityName :obj.stateName :obj.countryName:obj.fullAdd];
}
}
make a temp location class for temporary storage. And you can also save to the database as.
Enjoy Coding.
Even I noticed same issue. After many trail and error I found the problem with wifi I was using. If the signal strength is low you'll get city as nil. Try changing your connection.

Location Services permission don't get saved iOS

I have problem with the localization API in Core Location Services. I get the promt that request permission to the location services. If I click Allow and goes to Settings I can see that my app don't have permission.
This is my code in my GeoUtility class:
CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];
CLLocationManager *lm = [[CLLocationManager alloc] init];
[lm setPurpose:#"Need to verify your region"];
[lm startUpdatingLocation];
It's trigged by a viewController in the viewDidAppear
I also have added location-services under Required Devices Capabilites in my plist file.
Add CoreLocation.framework and MapKit.framework
And
in .h
#import <MapKit/MapKit.h>
CLLocationManager *locationManager;
CLGeocoder *geocoder;
in view did load
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
geocoder = [[CLGeocoder alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
then
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
LongitudeLbl.text = [NSString stringWithFormat:#"%.8f",currentLocation.coordinate.longitude];
LatitudeLbl.text = [NSString stringWithFormat:#"%.8f",currentLocation.coordinate.latitude];
}
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
NSString *addresstemp2 = [[NSString alloc] init];
NSString *subThoroughfare2 = [NSString stringWithFormat:#"%#",placemark.subThoroughfare];
NSString *thoroughfare2 = [NSString stringWithFormat:#"%#",placemark.thoroughfare];
NSString *postalCode2 = [NSString stringWithFormat:#"%#",placemark.postalCode];
NSString *locality2 = [NSString stringWithFormat:#"%#",placemark.locality];
NSString *administrativeArea2 = [NSString stringWithFormat:#"%#",placemark.administrativeArea];
NSString *country2 = [NSString stringWithFormat:#"%#",placemark.country];
if (![subThoroughfare2 isEqualToString:#"(null)"]) {
addresstemp2 = [NSString stringWithFormat:#"%#",subThoroughfare2];
}
if (![thoroughfare2 isEqualToString:#"(null)"]) {
addresstemp2 = [NSString stringWithFormat:#"%# %# \n",addresstemp2,thoroughfare2];
}
if (![postalCode2 isEqualToString:#"(null)"]) {
addresstemp2 = [NSString stringWithFormat:#"%# %#",addresstemp2,postalCode2];
}
if (![locality2 isEqualToString:#"(null)"]) {
addresstemp2 = [NSString stringWithFormat:#"%# %# \n",addresstemp2,locality2];
}
if (![administrativeArea2 isEqualToString:#"(null)"]) {
addresstemp2 = [NSString stringWithFormat:#"%# %# \n",addresstemp2,administrativeArea2];
}
if (![country2 isEqualToString:#"(null)"]) {
addresstemp2 = [NSString stringWithFormat:#"%# %#",addresstemp2,country2];
}
AddressLbl.text = [[NSString alloc] initWithString:addresstemp2];
[AddressLbl sizeToFit];
[locationManager stopUpdatingLocation];
} else {
}
} ];
}
And you also change setting in your Simulator GO TO THE setting and choose Location Service change it to ON. see down is your application name if it is off then change to ON

CLGeocoder not working

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[window addViewForTouchPriority:viewController.view];
if(self.locationManager==nil){
locationManager=[[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.purpose = #"We will try to tell you where you are if you get lost";
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=500;
self.locationManager=locationManager;
}
geoCoder = [[CLGeocoder alloc] init];
if([CLLocationManager locationServicesEnabled]){
[self.locationManager startUpdatingLocation];
}
return YES;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
lati = [[NSString alloc] initWithFormat:#"%+.6f", newLocation.coordinate.latitude];
NSLog(#"address:%#",lati);
longi = [[NSString alloc] initWithFormat:#"%+.6f", newLocation.coordinate.longitude];
NSLog(#"address:%#",longi);
CLLocationCoordinate2D coord;
coord.latitude = [lati doubleValue];
coord.longitude = [longi doubleValue];
[geoCoder reverseGeocodeLocation: newLocation completionHandler: ^(NSArray *placemarks, NSError *error)
{
//Get nearby address
CLPlacemark *placemark = [placemarks objectAtIndex:0];
//String to hold address
NSString *locatedAt = [[placemark.addressDictionary valueForKey:#"FormattedAddressLines"] componentsJoinedByString:#", "];
//Print the location to console
NSLog(#"I am currently at %#",locatedAt);
address = [[NSString alloc]initWithString:locatedAt];
NSLog(#"address:%#",address);
}];
}
I am using above code to get address by giving latitude and longitude, but control is not entering in to geocoder method, it skips it. Can anybody help me in it.
Thanks in advance.
It doesn't matter, control does not enter in the method, but it works, note the output it will work.
that is normal, because the code inside the reverseGeocodeLocation is execute inside a block.
The execution of the code inside a block occurs in another thread, so is not execute in the main thread, that's why the control don't enter inside the geocoder method.

iOS forward geocoding block not being executed

Why this block of code isn't being executed? I copied and pasted it from another project of mine, where it works just fine. I also tried it in my other app with the same addressString I'm plugging in here, and it worked perfectly.
NSString *addressString = [NSString stringWithFormat:#"%# and %#, %#, NY", street, rightBound, [boroughs objectForKey:borough]];
NSLog(#"Address string: %#",addressString);
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(#"Placemark count:%d",[placemarks count]);
for(CLPlacemark *placemark in placemarks)
{
NSLog(#"%#",placemark);
}
if(anError)
{
NSLog(#"Error: %#",[error description]);
}
}];
Neither any placemarks nor an error message is logged to the console.
Here is my entire AppDelegate.m:
#implementation AppDelegate
#synthesize window = _window;
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSError *error = nil;
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSString *JSONString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Streets" ofType:#"json"] encoding:NSUTF8StringEncoding error:&error];
if(error)
{
NSLog(#"%#",[error description]);
NSLog(#"Break");
}
NSDictionary *dict = [parser objectWithString:JSONString error:&error];
if(error)
{
NSLog(#"%#",[error description]);
NSLog(#"Break");
}
NSArray *addresses = [[dict objectForKey:#"results"] retain];
NSDictionary *boroughs = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:#"Bronx",#"Brooklyn",#"New York", #"Queens",#"Staten Island",nil] forKeys:[NSArray arrayWithObjects:#"B",#"K",#"M",#"Q",#"S", nil]];
int i = 1;
for(NSDictionary *file in addresses)
{
NSString *borough = [file objectForKey:#"Borough"];
NSString *ID = [file objectForKey:#"ID"];
NSString *leftBound = [file objectForKey:#"LeftBound"];
NSString *rightBound = [file objectForKey:#"RightBound"];
NSString *sideOfStreet = [file objectForKey:#"SideOfStreet"];
NSString *street = [file objectForKey:#"Street"];
NSString *addressString = [NSString stringWithFormat:#"%# and %#, %#, NY", street, rightBound, [boroughs objectForKey:borough]];
// NSLog(#"Address string: %#",addressString);
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)
{
NSLog(#"AAAAAAAAAAAAAAAAAAAAAAAA");
NSLog(#"Placemark count:%d",[placemarks count]);
for(CLPlacemark *placemark in placemarks)
{
NSLog(#"Placemark: %#",placemark);
}
if(anError)
{
NSLog(#"Error: %#",[error description]);
}
}];
[geocoder release];
NSLog(#"%d",i++);
}
[parser release];
[addresses release];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqualToString:#"geocoder"])
{
NSLog(#"AAAAAAA");
}
}
#end
Have you made sure your "geocoder" instance is not nil?
Nothing will happen if you send a message to a "nil" object... :)
NSLog(#"%#",geocoder);
I'm still not sure what's going on. I ran the following code (original code minus the JSON operations) on my simulator and it worked perfectly. Maybe you need a fresh install of Xcode & iOS Simulator?
#implementation AppDelegate
#synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *addressString = [NSString stringWithFormat:#"1 Infinite Loop, Cupertino, CA"];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)
{
NSLog(#"AAAAAAAAAAAAAAAAAAAAAAAA");
NSLog(#"Placemark count:%d",[placemarks count]);
for(CLPlacemark *placemark in placemarks)
{
NSLog(#"Placemark: %#",placemark);
}
if(anError)
{
NSLog(#"Error: %#",[anError description]);
}
}];
[geocoder release];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#end
Output was:
2011-12-21 18:56:30.311 Test[44445:f803] AAAAAAAAAAAAAAAAAAAAAAAA
2011-12-21 18:56:30.312 Test[44445:f803] Placemark count:1
2011-12-21 18:56:30.314 Test[44445:f803] Placemark: 1 Infinite Loop, Cupertino, CA 95014-2083, United States # <+37.33168400,-122.03075800> +/- 100.00m, region (identifier <+37.33168400,-122.03075800> radius 71.01) <+37.33168400,-122.03075800> radius 71.01m
The only thing I can think of is that you may be releasing your geocoder too early! Maybe try moving the release into the block? This way, you'll know the geocoder is only being released once after it has finished the geocode operation.
Also, you made a mistake with your error handling inside the block.
It should be NSLog(#"Error: %#",[anError description]);
instead of NSLog(#"Error: %#",[error description]);.
Also, make sure you're not using ARC...
I know this is an old question but the reason this doesn't work is you cannot make multiple forward requests simultaneously. You must check the property isGeocoding before sending another one.