2012-10-06 156 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

相关问题