Friday, February 5, 2010

This Week in iPhone & iPad News - Februrary 5/2010

With the iPad announcement from last week, there are now many news items on both the iPad and the iPhone. Take a look at the latest batch.


Friday, January 29, 2010

This Week in iPad News - January 29/2010

Due to this week's announcement of the iPad, the normal "This Week in iPhone News" has been pre-empted by the iPad news that came out.


Friday, January 22, 2010

This Week in iPhone News - January 22/2010

Some of the more interesting iPhone news items of the week.


Friday, January 15, 2010

This Week in iPhone News - January 15/2010

Catch up on the latest in iPhone news this week!


Saturday, January 9, 2010

This Week in iPhone News - January 08/2010

Take a look at some of the more noteworthy iPhone news items of the week.


Tuesday, December 29, 2009

The Curious Case of MKReverseGeocoder

Lately I've been working on an iPhone application that includes the use of a Google map by way of the MapKit libraries.

When showing the user's current location, there are a few ways to go about it. If you simply want the MapView instance to take care of it, you can set "showsUserLocation" to true and the MapView instance will use the GPS hardware to locate your position and place the familiar blue dot with the accuracy circle around it on the map. However, if you want to zoom in on that position, it's up to you to manage.

If you want more control or if you're placing a custom "placemark" (pushpin, etc.) onto the map, there are two main ways of doing it. The easiest and most often quoted method in tutorials involves the use of the MKReverseGeocoder library. What this does is allow you create an instance of the MKReverseGeocoder class and initialize it with a CLLocationCoordinate2D object. You then assign a delegate and then tell the MKReverseGeocoder instance to start via its start method.

The two delegate methods you're interested in when dealing with the MKReverseGeocoder library are:

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
and
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
What MKReverseGeocoder does is take a given location object (containing geocoordinate information in the form of latitude and longitude) and make a call to Google's API using an HTTP POST in order to determine what the closest address is. If the lookup is successful, didFindPlacemark: is called, but if it's note, didFailWithError: is called.

When I initially started development on this application, I never saw didFailWithError: being called for locations I gave to the MKReverseGeocoder instance. However, about a few weeks ago, I started noticing that I was consistently getting didFailWithError: ONLY after 5PM PST. A coordinate that successfully resolved to an address during the day mysteriously stopped resolving after 5PM PST. The error that was being returned was:
PBRequesterErrorDomain error 6001
While this isn't very descriptive, I did a bit of searching online (using Google ironically) and found that a few other developers have started to see this behavior recently as well.

What turns out to be happening is that the HTTP POST that is being done by the MKReverseGeocoder library to Google's servers is being met with a 503 Service Unavailable error at certain times of the day (for me it's consistently between 5PM and around 9AM PST).

I have verified this by capturing the packets when using either the iPhone simulator or my iPhone while on my local WiFi network or on 3G. The following reconstruction of the packets in question:

POST /glm/mmap HTTP/1.1
Host: www.google.com
User-Agent: Apple iPhone v7D11 Maps v3.1.2
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 89
Connection: keep-alive

../+.N.8.Z..en_US.&com.apple.iphone simulator-com.foobar..
3.1.2.7D11>...
.. ............HTTP/1.1 200 OK
Content-Type: application/binary
Content-Length: 13
Date: Mon, 28 Dec 2009 02:51:50 GMT
Expires: Mon, 28 Dec 2009 02:51:50 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Server: GFE/2.0

..>....
.359.POST /glm/mmap HTTP/1.1
Host: www.google.com
User-Agent: MyApp/1.0 CFNetwork/459 Darwin/9.8.0
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 181
Connection: keep-alive

../+.N.8.Z..en_US.&com.apple.iphone simulator-com.foobar..
3.1.2.7D11)...k.i
=
.7D11..iPhone OS.#2:FeAFHCc8yFilvsrw:7TjBQIp9ijRdhsXJ*.en_US.
.com.foobar."...


......P..".
...... .HTTP/1.1 503 Service Unavailable
Content-Type: text/html; charset=UTF-8
Date: Mon, 28 Dec 2009 02:51:54 GMT
Expires: Mon, 28 Dec 2009 02:51:54 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Server: GFE/2.0
Transfer-Encoding: chunked

a1
Service Unavailable
Error 503
As you can see, what MKReverseGeocoder is actually doing is making an HTTP POST call to http://google.com/glm/mmap.

Now I want to add that I am definitely not hitting some limit on the number of requests that I can be making since I have gone more than a day without testing this and then waited until the evening to make my first request which then failed, but in the morning after, it did not fail.

Now if Google is selectively turning off the web service that MKReverseGeocoder is relying on internally during a specific time period each day, it is something you definitely want to be aware of when using MKReverseGeocoder. Why they might be doing this is anyone's guess. In the meantime, I have submitted a bug report to Apple to see what they say. I have also made supporting posts on both Apple's private developer forum and public message boards where this behavior is also being seen, one of which includes:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/31883-pbrequestererrordomain-errors-reverse-geocoding.html#post155793
I have also verified that other iPhone applications already in the App Store are also exhibiting this behavior. If you download and install the "Gowalla" application, you will see that they are relying on the MKReverseGeocoder library to resolve your current location's address in their gold GPS bar at the bottom of the screen. During the times of 5PM - 9AM PST, I am noticing that it is "stuck" saying "Finding address...". At other times it is successfully resolving the address of your current location as found by the GPS.

What can you do in the meantime? There is another way to place placemarks on the map if you have a geolocation coordinate that doesn't involve the use of MKReverseGeocoder but instead uses the addAnnotation method in the MapView class:
- (void)addAnnotation:(id )annotation
In order to create an annotation object to be added to the map, you'll want to create a MapAnnotation class that inherits from MKAnnotation. The members of this class should include:
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
MapAnnotationType annotationType;
where annotationType is an enumeration where you can customize different placemark graphics for different types.

You also need to define a method with which to use during the object's initialization:
-initWithCoordinate:(CLLocationCoordinate2D)inCoord;
All you then need to do is instantiate your MapAnnotation class, passing the geocoordinate where you want the placemark to appear on the map. Then add this instance to your MapView instance via the MapView's addAnnotation method. The MKMapViewDelegate methods that you should be listening to in the class that you're using for all of this will then message the following method:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation;
At this point, you can check the annotation type to show custom placemark graphics, or you could just place a generic color pin, etc. Either way, you will need to return an instance of the MKAnnotationView class for your placemark to appear on the map.

Unfortunately, if you have a geocoordinate and absolutely need to display the address but don't know what it is, if you're relying on the Google functionality that is used by the MapKit library, I'm not sure what you can do at the moment. There are other alternatives to using MapKit that I won't go into here but beware of using MapKit if you're depending on resolving a physical address given a geocoordinate.

Any input is welcome and I will update this post with any updates that I may find in the future.

Update:

"edpark" on the iPhone dev SDK forum makes a good point:
Here's my theory. We know that Google throttles reverse-geocoding requests by IP. My suspicion is that this throttling is reset at midnight each night and that MKReverseGeocoder passes its requests through a centralized caching proxy; since that proxy would appear as a single IP to Google, it stops working at a certain point during the day.


Friday, December 18, 2009

This Week in iPhone News - December 18/2009

Need to catch up on the latest in iPhone news? Take a look!


Friday, December 11, 2009

This Week in iPhone News - December 11/2009

Only a few more weeks left for 2009. Amazing how time flies isn't it? Take a look at this week's iPhone news.


Friday, December 4, 2009

This Week in iPhone News - December 4/2009

Has it been a week already? Time for the latest in iPhone news that happened this week.


Monday, November 30, 2009

This Week in iPhone News - November 27/2009

The latest installment of iPhone news is now up, if a few days late :)


Thursday, November 26, 2009

IRC

Use IRC? I created a new channel #aribraginsky on irc.freenode.net (port 6667) where people can hang out and discuss things with me in real-time. For now, not much will be going on but I did setup Github to push out commit digest info into the channel.

I don't promise to be there 100% of the time, but I'm almost always at a terminal that is connected to IRC.

Stop by and say hi!

Unfamiliar with IRC? IRC stands for Internet Relay Chat and was created in the late 1980s as a way for people to communicate in real-time over the Internet. There are various ways to connect but the easiest would be via the web using http://mibbit.com.


Github

I recently created a new repository on Github to hold my Flash prototypes.

For now, you can download and play with a simple StarField 3D animation I created recently. A demo is also available.


Friday, November 20, 2009

This Week in iPhone News - November 20/2009

A bunch of interesting stuff happened this week in the iPhone world. Take a look and check back here every week for the latest in iPhone and iPod Touch news.


Monday, November 16, 2009

The Dark Side

I'm finally getting around to setting the color schemes for the various IDEs that I use to a more darker color to help save my eyes.

There are many different resources that cover the IDE color scheme topic:

The current schemes I've decided on using include:
Do you have a favorite?


Friday, November 13, 2009

This Week in iPhone News - November 13/2009

It's that time again to take a look at this week's iPhone news!