2013-08-01 52 views
0

我想同時在地圖上顯示多個註記。我有的問題是,我有所有的經度和NSString ...無法投射指針以輸入'double'

我想將字符串轉換爲雙重,以便我可以傳遞給「CLLocationCoordinate2D」實例..但我得到的錯誤說:指針不能投型'雙'

locationCoordinate.latitude=(double)NearbyLocations.lat; 
locationCoordinate.latitude=(double)NearbyLocations.lng; 

這是我有問題的代碼的一部分。但是,你可能會看到我還沒有完成它。

NSMutableArray *locations= [[NSMutableArray alloc]init]; 
CLLocationCoordinate2D locationCoordinate; 
location *NearbyLocations; 
Annotation *annotatedLocations; 

//for (int i=0; i < locationOnMap.count;i++) { 


    annotatedLocations = [[Annotation alloc]init]; 

    locationCoordinate.latitude=(double)NearbyLocations.lat; 
    locationCoordinate.latitude=(double)NearbyLocations.lng; 
    annotatedLocations.coordinate=locationCoordinate; 
    annotatedLocations.title=NearbyLocations.lo_name; 
    annotatedLocations.subtitle=NearbyLocations.lo_vicinity; 
    [locations addObject:annotatedLocations]; 
//} 

我能做些什麼來輸入字符串投點爲雙

+0

您正在使用哪種語言? –

+0

Marc,它看起來非常像Objective-C – akalenuk

+0

所以對不起,我正在使用Objective-c!完全忘了說! – Mohammed

回答

2

這意味着你想要將NSNumber的objective-c對象轉換爲C原始類型,這是不可能的。要將整數添加到字典中,必須將其轉換爲NSNumber對象。要拔出它,您必須將其轉換回來,如下所示:

locationCoordinate.latitude = [NearbyLocations.lat doubleValue]; 
locationCoordinate.latitude = [NearbyLocations.lng doubleValue];