Xcode GeoCoding initWithCoordinate function is messing up the Thoroughfare and other 2 fields when reading back from MapItem

StackOverflow https://stackoverflow.com/questions/21683121

Question

I wonder if anyone has seen this before, I think there is a bug in Xcode on the GeoCoding routine of (initWithCoordinate) where an address's PlaceMark (MKPlaceMark) is placed into a MapItem.

Consider the code below, after I got back a GeoCoded location i.e. Lat/Lon into a text-type-address via CLPlaceMark, I am looping through the result to convert these into MKPlaceMark's and storing them as MapItems, however, in run-time, I realised that Xcode/IOS is copying most address keys fine, but messing up the Keys of (SubAdminArea, SubThoroughfare, and Thoroughfare) which are very important for an address. Please see the snippet of my code below:

         for (int i=0; i < PlaceMarks.count; i++)
         {
             PlaceMark_CL = [PlaceMarks objectAtIndex:i];
             PlaceMark_MK = [[MKPlacemark alloc] initWithCoordinate:PlaceMark_CL.location.coordinate addressDictionary:PlaceMark_CL.addressDictionary];
             MapItem = [MapItem initWithPlacemark:PlaceMark_MK];
             [MapItem setName:PlaceMark_MK.name];


             NSLog(@"GeoCoded: SubLocality: '%@ / %@', Locality: '%@ / %@', AdministrativeArea: '%@ / %@', Country: '%@ / %@', CountryCode: '%@ / %@', InLandWater: '%@ / %@', ISOCode: '%@ / %@', Name: '%@ / %@', Ocean: '%@ / %@', PostCode: '%@ / %@', SubAdminArea: '%@ / %@', SubLocality: '%@ / %@', SubThoroughfare: '%@ / %@', Thoroughfare: '%@ / %@', Title: '%@ / %@'"
                   , [PlaceMark_MK subLocality]
                   , MapItem.placemark.subLocality
                   , [PlaceMark_MK locality]
                   , MapItem.placemark.locality
                   , [PlaceMark_MK administrativeArea]
                   , MapItem.placemark.administrativeArea
                   , [PlaceMark_MK country]
                   , MapItem.placemark.country
                   , [PlaceMark_MK countryCode]
                   , MapItem.placemark.countryCode
                   , [PlaceMark_MK inlandWater]
                   , MapItem.placemark.inlandWater
                   , [PlaceMark_MK ISOcountryCode]
                   , MapItem.placemark.ISOcountryCode
                   , [PlaceMark_MK name]
                   , MapItem.placemark.name
                   , [PlaceMark_MK ocean]
                   , MapItem.placemark.ocean
                   , [PlaceMark_MK postalCode]
                   , MapItem.placemark.postalCode
                   , [PlaceMark_MK subAdministrativeArea]
                   , MapItem.placemark.subAdministrativeArea
                   , [PlaceMark_MK subLocality]
                   , MapItem.placemark.subLocality
                   , [PlaceMark_MK subThoroughfare]
                   , MapItem.placemark.subThoroughfare
                   , [PlaceMark_MK thoroughfare]
                   , MapItem.placemark.thoroughfare
                   , [PlaceMark_MK title]
                   , MapItem.placemark.title
                   );

             [TempSearchResultsSorted addObject:MapItem];
         }

Well, with the above, almost all are copied ok, and extracted fine, however, sadly in regards to the 3 Keys mentioned above, upon copying from MKPlaceMark into a MapItem object via the standard (initWithCoordinate) routine and then reading it back in, I am seeing the following output to be different for the 3 Keys mentioned above, from the output (the one before / is the "before" value, and the one after is the "after" value):

SubAdminArea: 'London / (null)' SubThoroughfare: '21–35 / (null)' Thoroughfare: 'Hanover Road / 21–35 Hanover Road'

I wonder if anyone has seen this bug, or if you guys can suggest anything else.

Also, I tried to manually overwrite the bad ones with:

             [MapItem setValue:[PlaceMark_MK thoroughfare] forKey:@"thoroughfare"];

However, got an error as this wouldn't work, not sure if you guys have seen this.

What do you think?

Thanks & Regards,

Heider Sati

---------------------------------------- Edit: (2 hours later) ...

Furthermore, I just going through the dictionary items generated by each function to only find out that I am GobSmacked for how the MKMapItem ignores the 3 elements altogether and only "shadows" the output when requested as the exact values do not exists in the new dictionary, please see the code below that I used to dump the contents:

             NSLog(@"CL:");
             for (NSString *Key in PlaceMark_CL.addressDictionary)
             {
                 id Value = [PlaceMark_CL.addressDictionary objectForKey:Key];
                 NSLog(@"%@, = '%@', ", Key, Value);
             }

             NSLog(@"MK:");
             for (NSString *Key in PlaceMark_MK.addressDictionary)
             {
                 id Value = [PlaceMark_MK.addressDictionary objectForKey:Key];
                 NSLog(@"%@, = '%@', ", Key, Value);
             }

             NSLog(@"MI:");
             for (NSString *Key in MapItem.placemark.addressDictionary)
             {
                 id Value = [MapItem.placemark.addressDictionary objectForKey:Key];
                 NSLog(@"%@, = '%@', ", Key, Value);
             }

Using the above, you can see clearly that under the MI section from the dictionary, the 3 elements of (Thoroughfare, SubThoroughfare and SubAdminArea) are not copied into the dictionary of MKMapItem !, I think I will be relying on a hand-made dictionary to store these in for now unless someone knows anything better.

I hope this helps if you are having the same problem.

I will not mark the question as "answered" for now as I am about to speak to Apple to see if this is a bug or "feature" :)

Kind Regards Heider

-----------------------------------------> Edited, an hour later...

I just submitted a bug-report to Apple, reference no: 16026923, I hope to hear from them soon.

No correct solution

OTHER TIPS

After speaking with Apple regarding the bug above, this has been fixed in IOS-8, I tested it and confirm to be working now.

Regards Heider

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top