2012-01-10 30 views
0

我使用的是反向地理編碼,我想保存信息到一個SQLite數據庫,但我需要用戶設置的緯度和經度,但它沒有被通過。 我有兩個雙打VAR所謂的經度和緯度,當我下面執行此代碼,它使用「隨機」雙打:通過VAR爲目標C座

CLLocation *locate = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude]; 

    CLGeocoder *geoCoderCL = [[CLGeocoder alloc] init]; 
    [geoCoderCL reverseGeocodeLocation: locate completionHandler: 
    ^(NSArray *placemarks, NSError *error) { 

     CLPlacemark *placemark = [placemarks objectAtIndex:0]; 

     Controller *mController = [[Controller alloc] init]; 
     MyObject *newposition = [[Meeting alloc]init]; 
     [newposition setLatitude:latitude]; 
     [newposition setLongitude:longitude]; 
     [newposition setMName:[NSString stringWithFormat:@"%@ %@",placemark.thoroughfare,placemark.subThoroughfare]]; 
     NSLog(@"%@ %@",placemark.thoroughfare,placemark.subThoroughfare); 
     [mController createRecentPoint:newposition]; 
     [mController release]; 
     [newposition release]; 

    }]; 

如何應該這樣做嗎?謝謝。

回答

0

使用以下從CLPlacemark對象獲得的經度和緯度。

CLLocationDegrees latitude = placemark.location.coordinate.latitude; 
CLLocationDegrees longitude = placemark.location.coordinate.longitude; 

locationCLLocation對象。 coordinateCLLocationCoordinate2D struct和latitudelongitudeCLLocationDegrees(這僅僅是一個typdef'd double)。