We just put together some amount of code to fake the user's location.
Now one thing on mentioned very quickly is that you're not going to find any reference to this stuff
inside the expo documentation.
I just went through the source code found out how we actually change or Expo itself changes the user's
location and saw.
This is pretty much how they do it.
So not going to see this in the documentation just a little trick that is going to be very handy for
us to test out our application.
OK.
Now we've got all this fake location stuff put together.
We're gonna go back over to our track create screen and actually try to watch the user's location change
over time so to get started we're gonna find our import statement from Expo location and we're going
to import a second function here called Watch position async and then we're going to import something
else called accuracy
then right after we do our permissions request right here we're going to add in an a wait watch position
async so as you might guess this is going to watch the user's location and see it change over time.
The first argument is this function is going to be an options object inside of here we're going to define
an option of accuracy or accuracy is essentially how accurate we want our location reading to be.
We can go anywhere from a accuracy of like one to five kilometres all the way down to a like meter accuracy
the higher accuracy we asked for the more battery power it's going to take because our application is
all about watching the user's location and seeing it change over time and the user very possibly might
be like on foot or on a bike or something like that.
We probably want to have some very high accuracy so for accuracy right here I'm going to say accuracy
dot best for navigation.
Like so that means give us some very high accuracy in these readings after that we're gonna put in a
time interval that means 1000 right there that means that we want to try to get an update once every
second.
We'll also put in a distance interval of 10 and that means that we should also try to get an update
once every 10 meters.
So either once every second or once every 10 meters one or the other now is the second argument to watch
position async we're gonna put in a callback function so this callback function right here is going
to take some location object from the expo location library.
So this object right here describes the user's actual location.
So right now I'll just do a simple council log of their location and I'm just gonna try to print it
out at the terminal OK.
So that's pretty much it.
Now let's save this.
We're gonna test it out and see how this stuff all works together.
So I gotta say this code I'm going to go back over to my track create screen and then I'll go to my
terminal and once over there I should start to see a bunch of different console logs up here.
Now you're going to notice that we get some very different console logs.
Some of these have a timestamp of like whatever that is about 1 billion or so.
So those are the fake locations that we are now triggering.
Once per seconds you'll notice that I'm not really getting any console logs at all from the code that
we just added in.
Even though we kind of said right here that we wanted an update once every second.
So once again Expo location as a package I've not found that it's the most stable thing around.
So for whatever reason it's really just not giving me an update once every second.
And that's why having this test location code we just put together is really handy.
So no matter what while we are testing our application we know that we'll always get one update per
second guess that looks good.
Not gonna test this out on Android as well.
So I'll bring up my Android device.
Go to try track create then if I flip back over once again I should see these kind of fake locations
being emitted once every second here.
So it looks pretty good.
We've now got some fake blue date location data popping out here.
So now we can start to track this information and use it to show the user's current spot on the map
and then eventually record this information and draw it on the map as a line as well.
So a quick pause and I'll see you in just a minute.