[英]CLLocationCoordinate2D gets weird values after being passed
這是我第一次在目標C中為IOS編程,請耐心等待。
基本上,傳遞對象后,我的CLLocationCoordinate2D值會自行更改。
首先,此方法應模擬一個數據庫
/* *
* Static getMarkers
* Returns an NSMutableArray of CustomMarkers
* */
+ (NSMutableArray*) getMarkers
{
NSMutableArray * markers = [[NSMutableArray alloc] init];
CLLocationCoordinate2D projection = CLLocationCoordinate2DMake(50.850282, 4.351932);
CustomMarker *m = [[CustomMarker alloc] initWithTEN:@"Brussels"
TFR:@"Bruxelles Centre"
TNL:@"Brussel Centrum"
Position:&projection
Filename:@"FILE.TXT"
MarkerType:Verhaal];
[markers addObject:m];
return markers;
}
當我在這些行上設置斷點時,一切都完美無缺。
然后,當我嘗試在視圖控制器的循環中使用標記時,它變得很丑陋。
// Load markers from datahelper
NSMutableArray * markers = [DataHelper getMarkers];
// Put the loaded markers on the map
for (CustomMarker *lm in markers) {
在這里,一旦從datahelper接收到標記,位置就會錯誤。
我遇到的另一個問題是,枚舉MarkerType從一開始就是零。
謝謝您的幫助!
您的參數不應為(CLLocationCoordinate2D*)position
,而應為(CLLocationCoordinate2D)position
。 然后,您可以停止傳遞指針。
您的問題更有可能是gmsm.position = *(lm.Position);
或(*lm.Position).latitude, (*lm.Position).longitude
。 基本上,不要在位置混亂的地方使用指向位置結構的指針,而是訪問錯誤的內存位置(就像取消引用指向CustomMarker
實例的有效指針一樣)。
如果將投影作為&projection
傳遞,則通常意味着傳遞給它的initWithTEN...
方法可能出於某些原因想要更改投影。 檢查文檔,或者如果您有資料來源,請使用該方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.