问题
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