2011-05-11 129 views
0

我正在使用mapkit並在數據庫中的雙重類型中使用瘦代碼分配緯度和經度時出錯

 double  latitude1; 
    double  longitude1; 
@property (assign) double latitude1; 
@property (assign) double longitude1; 

緯度和經度但是當我寫這行時我收到錯誤:(

CLLocationCoordinate2D theCoordinate; 
     theCoordinate.latitude = [ classObj.latitude1 doubleValue]; 
     theCoordinate.longitude = [ classObj.longitude1 doubleValue]; 

此錯誤發生 「無效接收類型雙「 我有浮動轉換但它也沒有工作..

+0

您是否使用了@synthesize來生成getter?並且不要爲原始類型使用assign。 – 2011-05-11 11:40:23

+0

'@synthesize latitude1,longitude1' – 2011-05-11 11:42:06

回答

0

latitude1財產我已經是簡單的雙重 - 你不需要(也不能使用)doubleValue調用。只要寫:

theCoordinate.latitude = classObj.latitude1; 

甚至更​​好

LLocationCoordinate2D theCoordinate = CLLocationCoordinate2DMake(classObj.latitude1, classObj.longitude1); 
+0

@ Vladimir.Thank you,Now its working。(^_^) – 2011-05-11 11:55:12

0

您定義latitude1和longitude1是雙

所以,你可以直接分配。

喜歡

CLLocationCoordinate2D theCoordinate; 
theCoordinate.latitude = classObj.latitude1; 
theCoordinate.longitude = classObj.longitude1; 
0

[classObj.latitude1的doubleValue]通常需要類型轉換時使用,但在CLLocationCoordinate2D的緯度和經度是兩倍。無需進行類型轉換,只需分配值即可。

CLLocationCoordinate2D theCoordinate; 
     theCoordinate.latitude = classObj.latitude1; 
     theCoordinate.longitude = classObj.longitude1;