2013-07-21 2 views
0

Google 역 지오 코딩을 사용하여 사용자의 현재 위치를 가져옵니다. 내 코드는 다음과 같이 구성됩니다.역 지오 코딩 (Google API)을 사용하여 거리 이름 추출

NSString* StrCurrentLongitude=[NSString stringWithFormat: @"%f", currentLocation.coordinate.longitude]; // string value 

    NSString* StrCurrentLatitude=[NSString stringWithFormat: @"%f", currentLocation.coordinate.latitude]; 

    [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true_or_false",StrCurrentLatitude,StrCurrentLongitude]]; 

이제 어떻게하면 사용자의 현재 위치를 계속 얻을 수 있습니까? 내 머리 위로의

답변

1

:

[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithUrl:yourURL] queue:[NSOperationQueue mainQueue] completion:^(NSURLResponse *r, NSData *d, NSError *e) { 
    //decode it 
    id json = [NSJSONSerialization JSONObjectWithData:d options:0 error:nil]; 

    //process google response, which is JSON IIRC 
}]; 
+0

이 NSURLResponse 또는을 NSData입니다 내가 받게 될 것이다 JSON 파일입니까? 어떻게 주소를 추출 할 수 있습니까 (아니면 구문 분석합니까?)? – HusseinB

+0

오, 내가 사용할 수있는 하나의 요청과 completionHandler 사이에 "대기열"을 가지고, 내가 그걸 넣어 무엇입니까? – HusseinB

+0

[NSOperationQueue mainQueue] - NSData에는 JSON이 있습니다. –