All right my friends in this video we're going to write out some code to trick all of our different
test devices be it a simulated device or a physical into thinking that the user's location is changing
over time.
So to get started I'm gonna go back over my code editor and inside of my S R C directory I'm going to
make a new file called underscore mock location dot J.S. so the idea is that this is kind of like a
test only file that's going to mark out our users location.
We would definitely not want to include this file inside of any kind of production build.
So over time are going to be kind of toggling an import statement to either include this file or not
use it at all.
All right.
So inside of here we're going to first add in a little import statement we're going to say import star
as location from Expo location.
So internally at the location library exports a ton of different named functions.
By using star as location we're essentially getting a single variable that references all those different
functions then right after that we're gonna write out a little constant variable right here you're going
to see why we are defining this in just a moment.
I'm going to say 10 meters with degrees and I'm going to define this as zero point zero zero zero one.
Like so so this represents 10 meters in longitude or latitude.
Now technically it's not exactly 10 meters in both longitude and latitude just because the actual physical
shape of the world.
But it's essentially close enough after that we're going to define a function called get location.
This is going to take a variable called increment that's essentially a counter variable so from this
function right here we are going to return an object that essentially is a fake location reading it's
going to fake out some fake longitude and latitude and timestamp.
This is going to be what actually kind of tricks the expo location into thinking that our physical or
our emulate device is moving around the world when it really isn't.
So inside of you're going to say return an object and I'm going to give this all the properties that
a normal location reading off a device would have.
We haven't really looked at what these different readings are but we will see them very quickly.
So first off I can give this thing a timestamp.
The timestamp can be any value which just has to be a number.
So I'm going to put in like 1 0 0 like so and then going to give it a coords property inside of here.
I'm gonna give it a speed of 0 a heading of zero an accuracy of 5 an altitude accuracy of 5 an altitude
of 5 and then here are the two that actually make her actually important for us we're going to do a
longitude of negative 120 2 0 3 1 2 1 8 6 and we're going to add on increment times 10 meters with degrees
and then 4 latitude we're gonna put in 3 7 3 3 2 3 3 1 4 1 increment times 10 meters with degrees now
the latitude and longitude that I just entered in here our fourth Apple headquarters once again in Cupertino.
So essentially we're going to start off our fake location tracking at Apple headquarters and then over
time we're going to add in just like 10 meters 10 meters 10 meters just kind of move the user around
the location or around the world.
All right.
Finally down at the very bottom this is where the real magic happens.
We're going to define a counter variable and set it to zero.
And we're going to set up a set interval function and I'm going to run this interval function once every
second.
So I'll put in 1000 milliseconds right there.
So now inside of here this is where we're going to really trick out Expo location.
We're going to say location dots event emitter dot emit.
We're going to do Expo dot location changed.
We're gonna pass in an object as a second argument.
We're going to say watch I.D. is location dot underscore get current watch I.D. and then location is
our get location function and we're going to pass in that counter and then after we emit that event
I'm going to do a counter plus plus like so.
All right.
I know that's a lot of typing but now we can really see exactly what's going on here.
So whenever we import this file into our project once every second we're going to emit an event directly
into the location library and we're essentially faking out as though the user's location has changed
in the real world the watch idea right here is just little bit of background code.
What's more important is location location right there that's going to have our fake location that is
going to be changing once every second over time.
So once every second we're going to get a changed land longitude and latitude by 10 meters.
So this is going to allow us to very easily test out all of our tracking code and actually make sure
that hey our application works on the user's location is changing over time.
And once again this is only for testing purposes.
So if we ever deploy our application we would want to make sure that we do not import this file into
our project.
So now that we've got this Together blessing I'm going to do is go back over to my track and create
screen and at the very top I'm going to add in an import for up one directory underscore mock location
like so.
Now in theory once every second we are triggering a new change in location inside of our app.
Now I do want you to know that as we start to test this you are going to initially start to see the
user's location on this map right here like jump around.
And the reason for that is that it's going to eventually conflict with the actual reading of where your
user is.
But we'll see that in action in just a moment.
OK.
So now we've got this put together.
We've got some test code right here.
We can now start to actually write out our tracking stuff back inside of a check create screen.
So let's take care of that in the next video.