How To Simulate GPS Movement in iOS

Be warned: doing this on Pokemon Go might get your account suspended for cheating.

Motivation

I live 25km away from Melbourne CBD and there are two Pokestops within 5km of my house. Compare this to the CBD where there are hundreds of Pokestops and Gym everywhere. It’s ridiculous.

How about needing to walk 10km to hatch one Poke egg? I understand that it is good to have a walk around, but in the cold rainy winter day, I’d prefer to stay home.

There must be a better way to enjoy this game than driving 25km to city just to play. Right?

Solution

Preparation

Steps

Drawing the map

Then put 3 in Speed (mph) field to simulate average walking speed. If you wanted to test the limit, I’ve tried 6 mph and it still counts for hatching eggs.

After that, search for the big city that you wanted to catch your Pokemon in. In my case, I entered Melbourne

Zoom in until you can see the roads clearly and you can start clicking to draw waypoints. I’d recommend to draw around 5–10km worth of waypoints to reduce repetition and looping. The longer the better.

This is my track:

After we are done with drawing tracks, scroll down and find the Export file section and press download

Congrats, you have done drawing your map and exporting it!

Processing the gpx file

The problem is, we can’t just use the file like that. Xcode wouldn’t understand it. So lets get pumping!

First just replace all this part:

With:

<gpx>

Then at the end of the file, just delete the lines:

</trkseg> </trk>

You should have something like this now:

That’s great! What follows is a bit tricky and not as straightforward. We will have to change the format of the data from this:

<trkpt lat="-37.8117843" lon="144.9566173"> 
<ele>62.000000</ele>
<time>2010-01-01T00:00:00Z</time>
</trkpt>

into this:

<wpt lat="-37.8117843" lon="144.9566173"><time>2010-01-01T00:00:00Z</time></wpt>

Doing them one by one is possible, but it takes a lot of time to say the least when you have hundreds of points. To make things simpler for us, let’s use Regular Expression or Regex. If you have never used Regex before, it is just a language rules that we can use to select, modify, extract or otherwise manipulate texts.

Now inside Sublime Text, open up the Find and Replace menu by pressing cmd+shift+f.

Click on the leftmost icon with a dot and asterisk symbol on it. There should be a popup saying Regular Expression when you hover over it.

Then in the Find field enter: \s+<trkpt\s(.+)\n.+\n\s+(.+)\n.+

And in the Replace field enter: \n<wpt $1$2</wpt>

You should have it looking like this:

Then just press Replace and OK when asked. Your waypoints should be transformed into Xcode readable file.

If you think what happened is totally ridiculous and looked like sorcery, you might be right. You can read the short explanation by going to Regex101, but I won’t go into details here. Regex is big topic by itself and there are many people smarter than me that has covered it in detail.

Your final gpx file should look like this:

Now you are ready to make your injector app!

Location injection app

– always be plugged in to the computer with Xcode
– as light as possible to take up less memory
– always run in the background

The first point is pretty easy.
Second point is also easy since we will just have one empty controller with nothing on it.

Now the third point is tricky. We can’t just run a new empty app as iOS will kill it after several minutes of no activity to save battery and memory. We have to force it to keep running by using this trick:

keep requesting location update in the background

With this two, I was able to keep the app running for several hours in the background while I play Pokemon Go.

Project Setup

After the project is created, we have to do several things:

Backgrounding Capabilities

Open the Info.plist on the project navigator and add these two keys in the plist:

The first line enables the location permission prompt.
Second line just help your app to not get closed during backgrounding.

Import files

Drag and drop the two files into your project navigator and select the Copy items if needed box.

Codes to prevent backgrounding

Open AppDelegate.swift and below import UIKit:

import CoreLocation

Make the AppDelegate class conforms to CLLocationManagerDelegate protocol

class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {

Add the locationManager property below the window property:

var window: UIWindow? let 
locationManager = CLLocationManager()

Add this function into the class:

Finally just call the function inside didFinishLaunching:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
location() return true
}

And the app is done!

Just launch it and you should see a white screen with a popup asking for location permission. Just tap on Allow.

If it doesn’t ask you for permission, just go to
Settings -> Privacy -> Location Services -> 'your app name' -> Always

There are better ways to debug this, but for the purpose of this tutorial, let’s just ignore the fact that we have a bug.

Injecting the location file

If it’s not there, press cmd+shift+y to bring it up.

Click the arrow button and you should see your gpx file listed:

Click on it and your app is done!

Catch ’em all

Open the Pokemon Go app and you should see your trainer walking around your pre-set path, passing through all the Pokestops and Pokemons!

I hope you enjoy the tutorial and let me know if you got any questions on the comment box below!

GPS error

Message from debugger: Terminated due to memory issue

Pokemon Go app will either:

– show GPS error
– reset your GPS to your real location

When that happens, just rerun the injector app and re-pick the gpx file. You will be good to go again!

I have not been able to find a more elegant solution that keeps iOS from killing the app. Let me know if you know a better way!

You have learned how to:

– create a map waypoint
– parse the gpx with regex
– create app that will stay active in the background by
– playing an empty mp3 file continuously
– continously updates location in the background
– cheat on Pokemon

Where to go from here?

– create another map path on beaches/port to catch that Magikarp (for Gyarados of course)
– use this technique to test (or cheat) all other GPS based apps
– write a comment in the box below 🙂

Thanks for reading yo!

Software Engineer in Silicon Valley | www.augusteo.com