开发者

Registration timer expired, but client is still registering! - Google geocoding error

I am trying to use these two lines to get lat/long info when given an address input.

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", theAddress];

NSString *locationString = [[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease];

It is weird that sometimes I get the lat, long info as quick as in 5 seconds and in other cases the app is stuck for about 5 mins and then it logs an开发者_如何学Python error stating "Registration timer expired, but client is still registering!"

It also gives the location info (ie result string wth lat/long info) as null.

I tried it a number of times and couldn't figure out what makes it work and what doesn't.

Has anybody encountered the same issue before or any advice on this pls.

Thanks


try below code its working fine with me.

CLLocationCoordinate2D coord=[self gettingLatandLonFromAddress:address];

  -(CLLocationCoordinate2D ) gettingLatandLonFromAddress:(NSString *)address
    {
        CLLocationCoordinate2D currentLoc;
        NSString *urlString=[NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        NSString *locationString=[NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:nil];
        NSArray *listItems = [locationString componentsSeparatedByString:@","];
        double latitude=0.0;
        double longitude=0.0;
        if([listItems count] >=4  && [ [listItems objectAtIndex:0] isEqualToString:@"200"]){
            latitude = [[listItems objectAtIndex:2] doubleValue];
            longitude = [[listItems objectAtIndex:3] doubleValue];
        }
        else{       
            NSLog(@"Error");        
        }

        currentLoc.latitude=latitude;
        currentLoc.longitude=longitude;
        return currentLoc;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜