Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

franium

macrumors member
Original poster
Nov 18, 2010
34
0
Hi,
I use this code to set a label with a location string
Code:
locationString = [[NSString alloc] initWithFormat:@"%@%@ - %@ %@%@",
						thoroughfare,subThoroughfare,postalCode,
						locality,countryCode];
	
locationLabel.text = locationString;
where thoroughfare, subThoroughfare, postalCode, locality,countryCode are obtained from a placemark.
Now, I'd like to visualize this string according the current locale. Have I specify a string format for each locale in which I'm interested or there is a simpler way to obtain this?
Thanks,
Fran
 
Now, I'd like to visualize this string according the current locale. Have I specify a string format for each locale in which I'm interested or there is a simpler way to obtain this?
Thanks,
Fran

Do you mean, that you want to adjust for different locales where, for example, the order of thoroughfare and subThoroughfare is different? Or something else?
 
Exactly... I know that I can do it controlling the locale and changing accordingly the ordering of thoroughfare, subThoroughfare, postalCode, locality and countryCode in
Code:
locationString = [[NSString alloc] initWithFormat:@"%@%@ - %@ %@%@",
						thoroughfare,subThoroughfare,postalCode,
						locality,countryCode];
but this becomes hard if I have to do it for each locale, so I want to know if there is a method that considers the locale.
 
I dealt with this in my App by dumping the MKPlacemark properties -- including addressDictionary; using appropriate test data you should be able to develop a useful heuristic which uses all of the available information.

Good luck :)
 
I dealt with this in my App by dumping the MKPlacemark properties -- including addressDictionary; using appropriate test data you should be able to develop a useful heuristic which uses all of the available information.

Good luck :)

I can't figure out how AddressDictionary could help me, really I don't understand very well what an AddressDictionary object represents :)
I'm working on not mine code and the reverse geocoder is created only so:
Code:
self.reverseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:coordinate] autorelease];
I'll search more info about Address Dictionary.
Thanks
 
I can't figure out how AddressDictionary could help me, really I don't understand very well what an AddressDictionary object represents :)
I'm working on not mine code and the reverse geocoder is created only so:
Code:
self.reverseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:coordinate] autorelease];
I'll search more info about Address Dictionary.
Thanks

Use the debugger or NSLog to inspect the placemark object you receive when MKReverseGeocoder succeeds. The adressDictionary property is particularly interesting... ;)
 
Use the debugger or NSLog to inspect the placemark object you receive when MKReverseGeocoder succeeds. The adressDictionary property is particularly interesting... ;)

I tried to access it, using for example
Code:
NSString *kABPersonAddressCityKey;
NSString *city = [placemark.addressDictionary objectForKey:(NSString*) kABPersonAddressCityKey];
NSLog(@"%s", city);
in
Code:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark;

but the app crashes.
Moreover, my doubt is this: if I create the reverseGeocoder with
Code:
self.reverseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:coordinate] autorelease];
can this cause a problem or has the placemark always an AddressDictionary not null?
 
The crash is because you have not initialized 'kABPersonAddressCityKey'.

Now, I can see what there is in the addressDictionary, with
Code:
NSLog(@"The geocoder has returned: %@", [placemark addressDictionary]);

and I see the interesting field "FormattedAddressLines".
Now, if I change the locale and language I see only a traduction of city and country, but I suppose that for example with american adresses I'll see first the street number and then the remain, won't I? But also in this case, my question is still there... that is... in the case of an american address I think it needs the amministrative area and sub-amministrative area, which are useless in an italian one, for example. Do I miss something?
 
I suggest that you use a representative sample of coordinates, located within various cities and various countries, and with that the reverse-geocode data you will be able to devise an appropriate heuristic.

There really is no right or wrong answer. Good luck!
 
I suggest that you use a representative sample of coordinates, located within various cities and various countries, and with that the reverse-geocode data you will be able to devise an appropriate heuristic.

There really is no right or wrong answer. Good luck!


Thank you for your patience :) For now I'll use only a combination of the FormattedAddressLines, State and Country, then with a bit of time I'll try your solution
Ciao :)
 
Hi,
another thing: did you succeeded in doing some tries to see how the reverse geocoding string is printed? I try to explain... I noted that without adding the "State", the location of Apple is printed
Code:
1 Infinite Loop - Cupertino, California 95014, US

I use
Code:
[formattedAddressLines objectAtIndex:0];
for print then "1 Infinite Loop"
Code:
[formattedAddressLines objectAtIndex:1];
for "Cupertino, California 95014"
Do you know if in USA, the State is always before zipcode?

I don't know if add also the state returned by:
Code:
NSString *state = [placemark.addressDictionary objectForKey:@"State"];
because I could have a state repetition
Thanks in advance.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.