views:

12

answers:

0

In the following Code i think i have a problem with timeouts, if the connection is slow. The application works with 3G and without net, but on GPRS it quits sometimes without a message in the log. I think, it maybe in this part of code.

So, is there a way to handle those timeouts ? Or have i done some stupid mistake, i havent figured out ?

-(CLLocationCoordinate2D) addressLocation {
    NSString *const APIKey = @"blablub";


    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv&key=%@",[adresse.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],APIKey];
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:nil ];
    NSArray* listItems = [locationString componentsSeparatedByString:@","];
    double latitude = 0;
    double longitude = 0;
    if ([listItems count]>=4 && [[listItems objectAtIndex:0] isEqualToString:@"200"])//200 ist der Google-Return-Code für success
    {
        latitude = [[listItems objectAtIndex:2] doubleValue];
        longitude = [[listItems objectAtIndex:3] doubleValue];
    }
    else {
        latitude = 0;
        longitude = 0;

    }

    CLLocationCoordinate2D location; //baue die 2D-Koordinate und gebe sie zurück
    location.latitude = latitude;
    location.longitude = longitude;


    return location;

}