2012-10-06 155 views
0

我得到了經度和緯度值,我將它保存在一個標籤中,它很容易顯示在我的應用程序中,但我想要當前的位置詳細信息,主要是該地點的名稱。
我用MKReverseGeocoder。我這樣做的代碼我如何獲得iPhone應用程序中的當前位置?

- (void)locationUpdate:(CLLocation *)location 
{ 
    CLLocationCoordinate2D coord; 
    coord.longitude=[NSString stringWithFormat:@"LATITUDE: %f", location.coordinate.latitude]; 

    MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc]initWithCoordinate:coord]; 
    [geocoder setDelegate:self]; 
    [geocoder start]; 



    latlbl.text = [NSString stringWithFormat:@"LATITUDE: %f", location.coordinate.latitude]; 
    lonlbl.text = [NSString stringWithFormat:@"LONGITUDE: %f", location.coordinate.longitude]; 
    //txtlocate.text = [location description]; 

} 
![-(void)reverseGeocoder:(MKReverseGeocoder)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
NSLog(@"%@",\[placemark addressDictionary\] 
    } 

enter image description here 這是我得到的錯誤...
預先感謝

回答

1

的錯誤是明顯的:

分配到 'CLLocationCoordinate2D' (又名'雙')來自不兼容類型「ID」

coordCLLocationCoordinate2D類型:

typedef struct { 
    CLLocationDegrees latitude; 
    CLLocationDegrees longitude; 
} CLLocationCoordinate2D; 

而且latitudelongitude是CLLocationDegrees:

typedef double CLLocationDegrees; 

所以你不能分配的NSString(這是一個id型兩種)對象coord.longitude也不coord.latitude


編輯:

你應該這樣做,如:

coord.longitude = location.coordinate.latitude; 
+0

ü可以解釋我簡單地會是怎樣的代碼 – goku

+0

我如何可以改變兩個座標爲雙? – goku

+0

@goku他們都是雙重類型,只是類型定義爲CLLocationDegrees。查看答案的新版本。 :) – Kjuly

相關問題