AGSLocator, AGSLocatorDelegate, AGSAddressCandidate Tutorial

1148
3
03-18-2010 09:39 AM
ChanceYohman
New Contributor
As promised, I've been developing code tutorials by digging into code and treating it like Legos. Ooh, what happens if I put this here? Attached is a tutorial using the above classes and protocols. The comments and questions I will spurt off are in the code. Please enjoy and participate in the discussion.

Important Note: For simplicity of implementation, everything is output to the console.

For the returnFields passed to the AGSLocator object via the locationsForAddress function, is there a better way to initialize the NSArray of Strings? There seems to be no notion of initializer lists in Objective-C and the NSArray class method arrayWithObjects doesn't appear to work with a parameter list of @"" string literals. Am I missing something here? What am I missing?

Where can I figure out the spatial reference for a GeocodeServer? I poked around the REST endpoint, but couldn't find the answer I wanted. Also, why does AGSPoint not return it's spatial reference through an accessor ("getter", I forgot if there is Apple specific term for this)?

Most importantly, look in the "This doesn't work?" block in the didFindLocationsForAddress method. It appears the NSDictionary address property is returned improperly. The count is null and there are 0 keys and values, respectively. Set a breakpoint on 150 and hover over candidate to inspect the candidate's address property.

Thanks for reading and composing any thoughts. 🙂
0 Kudos
3 Replies
MarkDostal
Esri Contributor
I've taken a quick look at the tutorials you put up and wanted to get back to you on one of your questions.  Concerning how to initialize a list of strings, you can use the 'arrayWithObjects' class method on NSArray:

    NSArray *returnFields = [NSArray arrayWithObjects:@"Loc_Name", @"Score", @"Side", nil];

The only tricky thing is to remember that the last element needs to be nil.

Also, there is an 'arrayWithObject', which takes a single object. Code completion sometimes picks up that one instead of 'arrayWithObjects'.

If you wanted to modify the array after it's been created, you can use NSMutableArray.

I hope to get to the rest soon; thanks for the effort!

Mark
0 Kudos
ChanceYohman
New Contributor
>I've taken a quick look at the tutorials you put up and wanted to get back to >you on one of your questions. Concerning how to initialize a list of strings, >you can use the 'arrayWithObjects' class method on NSArray:

>NSArray *returnFields = [NSArray arrayWithObjects:@"Loc_Name", >@"Score", @"Side", nil];

>The only tricky thing is to remember that the last element needs to be nil.

>Also, there is an 'arrayWithObject', which takes a single object. Code >completion sometimes picks up that one instead of 'arrayWithObjects'.

I retrieved that and it worked. I think my problem may have been picking up on arrayWithObject instead of arrayWithObjects, but I looked at that code long and hard. I'll try appending all the fields in there and see if I can recreate the problem. Thanks Mark.
0 Kudos
ChanceYohman
New Contributor
Okay, arrayWithObjects worked when I typed it out again with all of the parameters. Either I accidentally completed it as arrayWithObject or entered some extra whitespace in there that messed it up.
0 Kudos