Forward Geocoding in iOS4 and iOS5

Forward Geocoding

It is a common scenario that every developer has run into.

Locate places near me based upon a particular address and/or zip code.

In order to get the correct results the address needs to be converted to a lat/long coordinate. With iOS5 Apple has provided us with CLGeoCoder class which has convience methods for reverse/forward geocoding. Unfortunately, there isn’t really any built-in functionality for iOS4. Most current apps still have to support iOS4 so what are developers doing to fill the gap? Write their implementations for multiple OS support. Below is what I use.

** Note: I did use Sergio Martínez-Losa Del Rincón article as a starting point for the iOS4 support.

Techniques

  • Google’s Map API
  • CLGeoCoder
  • Objective-C blocks for callback
  • Grand Central Dispatch

Implementation

iOS5

I tackled the easiest solution first. Utilizing iOS5’s CLGeoCoding geocodeAddressString:completionHandler: . However, when I first use the method I kept getting back a location of {0.0,0.0} in my log. The reason being that I was neglecting the fact that the method executes asynchronously and doesn’t return its value. Hmmm….

Not too much of a hurdle thanks to the implementation of block handling. By adding a completionHandler to my own method I was able to provide a callback with the appropriate coordinate that I need after the request had finished.

iOS4

Duplicating the ease of the iOS5 functionality was a bit more involved. I created a category method on NSString (see the above referenced article for code origin. I did make updates to it.) for making a call to the Google Maps API and return their forward coding result. The method itself isn’t asynchronous because I wanted to leave the decision of whether or not to call the method async or sync up to the developer. To provide asynchrous support was easy just by utiliizing GCD.

Decision Time

Deciding which code block should the calling method execute was the final task to finish. Once again this was extremely simple.

if (NSClassFromString(@“CLGeocoder”)) { // ios5 } else { // everything else. in this case we are assuming there isn’t support for iOS3.x }

Code

The Case of Lost Text Messages and AT&T

Oct 14th, like millions of other people, got my iPhone 4S. Because I develop iOS apps I had been using iOS5 for a few months so to have both the new hardware and software together was nothing less than spectacular.  Many unfortunate users that day experience failed activations because of Apple's server overload. Since I didn't get mine until later that night I was able to shut off my iPhone4, activate the new phone and restore from iCloud without incident.  My new phone was BLAZING fast.  Siri, lived up to the height.  Cutting the cord with iTunes has made life so much more enjoyable.  Finally, I was able to communicate with the other iDevice people with iMessage in mass. It was a good day.

The next night at dinner a friend commented that she had texted me but I never responded. I didn't think too much of it because these things happen especially on iPhone launch/activation days due to network congestion.  Over the next few days I noticed that I wasn't receiving text messages from anyone other than iMessages and people weren't receiving mine.  Didn't matter the carrier.

After consulting the Google, I learned that many other people were experiencing similar issues, regardless of carrier or device version (4 and 4s).  It turns that with iOS5 there is a cap in the number of text messages that the messages app will support. After many frustrating hours with both Apple and AT&T, their "fix" was to wait for update from Apple, start deleting messages from your phone to free up space or wipe your phone and set it up as a new phone. By doing the last suggestion all your text messages would be gone.  I wasn't about to start all over with wiping my phone.  I deleted any of the old text messages that I could, but still no luck.  I waited a few days to see if either one of the carriers or Apple would break their radio silence on this issue and offer some support. Well….NOTHING.  While reading on the AT&T community support forum I notice that a moderator had reminded anyone having issues to check their account to make sure that they hadn't gone over their allotted number of texts.

When I checked my account I found something that will make me LOATH AT&T for quite sometime to come.

During the checkout process when I bought my phone I had to choose my data plan.  I still don't know why this was part of the process.  Maybe because I am one of the remaining few who have unlimited data and AT&T hates me. Regardless, I had to verify that I wanted to keep this plan. Apparently, AT&T found it fairly funny to remove my text messaging that I originally had. I mean why would someone assume that their current service features would still be there just because they are ordering a new phone.

Needless to say as soon as I added the text messaging back everything started working.

Carriers wonder why consumers and companies like Apple (iMessage), Google (GoogleVoice) and even Blackberry are doing whatever they can to bypass their unreliable networks, constantly changing terms/conditions and overall uncoolness towards consumers (hidden fees, data throttling, "upgrade fees", etc).

If you are having text messages check your account before you waste days and hours with wiping and restoring your phone.

Let's Talk iPhone Event

I always love the last few months and weeks that build up to an iPhone/iPad announcement.  Though some of the rumors have turned into fact, most are just random, fabricated factoids that many MSM and bloggers push out there for the masses.  At the end of the day I can only presume that Apple doesn't pay those any attention except in the case of lost hardware.

However, I am not immune to reading a lot of these misleading articles. Granted I don't treat them as gospel there are a few things that I am very excited about.

First, is the official roll out of iCloud.  Having used the beta version the past few months I have been pleasantly surprised as it's convince and ease of use.  It is a huge win for the average consumer who has, up to this point, been reliant on iTunes and various other backup strategies to manage their content and media.

Second, is iTunes Match.  It has always been somewhat of a let down that users couldn't access all of their music from any of their devices.  The process is extremely easy and now you don't have to carry around a separate iDevice to hold your music catalog.

Third, wireless syncing.  I have a strong feeling that most IT administrators and children/grandchildren who have to provide tech support to their parents/grandparents will jump up and down over this.

Fourth, the API features with the new iOS have once again raised the bar for app developers.  Apple has listen to feedback from developers to make it easier for us to provide better functionality in our apps as well as more detailed customization options.  

*Bye-bye drawRect: category*

Fifth (possibly), Apple Assistant.  Rumor Alert! Could the headline "Let's Talk iPhone" really have a hidden meaning.  
Apple gave the masses the first decent implementation of multi-touch.  The communication mechanism that is inherit to all since birth.  Pointing, dragging, panning, zooming, swiping.  With the acquisition of Siri, there is no doubt that Apple has been putting a lot of effort in creating the near-perfect implementation of voice recognition for the masses.  On device voice processing via natural speech that is a native part of iOS.  If this is the case, then you will see a whole new generation of apps and a paradigm shift in how users, impaired or not, interface with these applications.

Apple...let's talk.