I have a MapView that I’m trying to add an Annotation at the current Coordinates.
My Code in viewWillAppear:
CLLocationCoordinate2D location;
location.latitude = [maps.barLat doubleValue];
location.longitude = [maps.barLong doubleValue];
[_mapView addAnnotation:location];
I’m getting an error on the addAnnotation that says
Sending CLLocationCoordinate2D to parameter of incompatible type MKAnnotation.
All the other examples I see have no problem with this code, what am I missing?
If you look at Apple’s API docs, the
addAnnotation:method takes anid<MKAnnotation>, not aCLLocationCoordinate2D. That’s the reason for your error.If you just want a simple annotation, without any fancy bells or whistles, just do this:
Most people, however, wind up creating their own class that implements the
MKAnnotationprotocol, to provide custom annotations. But, if all you need is a pin, the above will work.