Error : Assigning to 'CLLocationCoordinate2D' from incompatible type 'id'

不羁岁月 提交于 2019-12-21 21:13:10

问题


Hai I am trying to display multiple annotations in mkmap. While am adding the coordinates it shows the error:"Assigning to 'CLLocationCoordinate2D' from incompatible type 'id'". I know this is a simple prob, but I have searched many times and tried a lot but none works, my code is,

for(int i=0 ; i<coordinates.count ; i++)
    {
     MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
     point.coordinate =[coordinates objectAtIndex:i]; //here it shows the error
     point.title = @"title";
     [self.mapView addAnnotation:point];
    }

kindly advice me to solve this prob. Thank you...


回答1:


As CLLocationCoordinate2D is not an Objective-C object, but a struct, it cannot be directly stored in an NSArray object, but rather it must be wrapped within an NSValue object.

Therefore the code to read co-ordinates from the array is probably:

CLLocationCoordinate2D coords;
[[coordinates objectAtIndex:i] getValue:&coords];
point.coordinate = coords;

However to know for sure, I would need to see how the array was created.



来源:https://stackoverflow.com/questions/24925546/error-assigning-to-cllocationcoordinate2d-from-incompatible-type-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!