To annotate the
MKMapView
with a circle,
we have to create two objects.
See the
Location
Awareness Programming Guide.
Annotation
,
which adopts the
MKAnnotation
protocol and holds a
CLLocationCoordinate2D
(latitude and longitude).
The
Annotation
must be created before its
AnnotationView
.
AnnotationView
,
derived from class
MKAnnotation
,
which is derived from class
UIView
.
The
AnnotationView
is created (or at least returned) by the
mapView:viewForAnnotation:
method of the
MKMapViewDelegate
.
main.m
MapAppDelegate
View
Annotation
AnnotationView
Map-Info.plist
To create class
View
,
File → New File… Objective-C class Subclass of UIView Next File Name: View.m ✓ Also create "View.h" Finish
Create class
Annotation
as a subclass of
NSObject
,
and class
AnnotationView
as a subclass of
UIView
.
Thenedit
AnnotationView.h
and change it to a subclass of
MKAnnotationView
.
Add the Core Location and Map Kit frameworks:
Project →
Edit Active Target "Map" →
General →
Linked Libraries
You should already have three frameworks:
Foundation, UIKit, and Core Graphics.
Press the plus sign and add
CoreLocation.framework
MapKit.framework
.
Allow the app to run only on a device that has the required device capabilities.
Add a new property to the file
Map-Info.plist
Resources
folder of the project.
Display the file in the lower right pane of Xcode.
Click on the plus sign,
scroll down to
Required
device capabilities,
and select it.
Then click on the triangle to make it point down,
and add the item
location-services
.