close
pokemon-1581774_1920

Pokemon Go is very famous mobile app. What we are doing here is similar to Pokemon Go in iOS using MapKit. The simplest way of implementing Pokemon Go using MapKit in iOS.

This is the flow which we will follow:
  1. Setting up the View
  2. Asking for permission of location
  3. Heading
  4. Custom Annotation

Setting up the View

Insert a map view in a ViewController and make it’s IBOutlet as
In your header (.h) file of viewController
Add <MKMapViewDelegate, CLLocationManagerDelegate> in @interface as

and after this put CLLocationManager *locationManager; }

Asking for permission of location

Open Info.plist and add

This is how it’ll look like.

info.plist-location-permission
In your – (void)viewDidLoad add

Now suppose user has denied the location request. And your app is a must for location service of user. You need to display an alert that user should allow the location. For that you need to call this method:

To allow the map to center on user location add this delegate method.

Now run the app and you’ll see it is working great.

mapkit-with-annotation

Heading

Heading is the indicator that will show in which direction the user is heading towards. This is the thing that will give you the Pokemon Go type look look.
Goto your .h file and add this @import CoreMotion; after #import
Make this @property (strong, nonatomic) CMMotionManager *motionManager;
Open .m file add

in viewDidLoad after the if statement of requestWhenInUseAuthorization.

Update viewWillApear method as:

That’s it! Run the code on your phone. As you can’t track it on stimulator and you can see a heading head. As you rotate your phone it’ll rotate as per your direction.

As in Pokemon Go the user point in a little towards the bottom of the screen as shown in this picture below.
pokemon-go
See it’s not in the center and it’s 3D. It can be achieved by a simple delegate method of MKMapView ofcourse not the 3D part just the default center of the map.

Run the code and see the change. For now comment this code and change the annotation from custom annotation below.

 Custom Annotation

As we have changed the image of our default user location annotation let’s dive in and do something more with it.
Import SVPulsingAnnotationView.h and SVPulsingAnnotationView.m into your project.
Import #import “SVPulsingAnnotationView.h” in your header (.h) file
Update the above function as
By using this class you can do a lot with this annotation now. You can explore that yourself and try to do a lot of good with it.
What you saw above the simplest way of implementing Pokemon go in iOS using mapkit.
Chaudhary Talha

The author Chaudhary Talha

I'm an iOS developer by profession and UI/UX designer by passion. All my tutorials are based on my personal experiences and whenever I learn something new I share it with the world.
x
Like what we are doing? Join Us! Become a contributor at iOS Pakistan.