Your Great Journey Starts here.

Draw polygon or polyline on MKMapView with stylus

MapKit allows you to display maps, navigate through maps, add annotations for specific locations, add overlays on existing maps, in this tutorial you will learn how to draw a polygon on map with free hand.

Creating the Project:

First, create a new Xcode project using the Single View Template. Then type FreeHandDrawMap as the project name as shown below.

Design the Interface:

Click on ViewController.xib to bring up Interface Builder. Drag a toolbar to the bottom of the screen, Map View to the middle of the screen and two bar buttons on the bar from Object library. Then rename the toolbar buttons to Draw Map, ”Save Map” and “View Map”.

Frameworks required:

Before you can run your code, add these two frameworks to the project.

CoreLocation

MapKit

let’s run the app and see how it looks like.

Control-drag from the Map View down to your header file.A popup will appear. Set the connection type to Outlet, the name to mapView. Do the same things for the buttons, but when the pop-up menu goes on, select the Connection as “Action” then name them As drawMap, saveMap, viewMap.

Go to ViewController.m, and add MKMapViewDelegateas shown below

Add the following instance variables in @interface section as shown below