2013-07-21 87 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 –

相關問題