Now we can see what the user's current location is.
We can start to really think about architecting our application.
So what do I mean by that.
Well we're gonna have some really complex interactions between this location update right here our map
and the overall data flowing out throughout our application.
Anytime we see a location update we need to make sure that we take that current location and we use
it to update the center point of our map right here.
So we always want to send to the map on wherever the user actually is.
In addition we want to make sure that if the user is currently recording a track we also somehow record
this location as well and stored inside of an array or something like that to indicate that this is
a point that a user pass through while they were recording a track.
So to coordinate all this stuff and all this flow of information we're going to add in some kind of
complex architecture to our app.
Here's essentially what we're going to do.
So we're going to add in a new piece of context something called our location provider.
This is going to hold some information related to the user's current location in the world and related
to the ability to create a new track and then eventually save it.
So inside this location provider we're going to record the user's most recent location as a flag called
current location.
We're going to record whether or not the user is currently recording a track under a flag called recording
and then finally it will store a list of locations that the user has passed through.
So we're going to have all this information available to our track create screen the track form and
the map.
Remember the track form is going to be that form right there down at the bottom and has that big record
button on their All right.
Now the actual kind of way in which this stuff works together is unfortunately a little bit complicated.
So going to show you another diagram that's going to kind of expand on this architecture a little bit
and give you a better idea of what's going on.
OK.
So this is essentially the final kind of form of what we're going for.
So in this diagram I cut out a couple of things you saw in the last one.
So at the very top we do have our location provider again location providers going to store the user's
most recent location as something called current location.
It will have that recording boolean and then an array of locations.
One of the most important things we want to focus on right now is making sure that the current location
where the user's most recent location that was red somehow gets placed or sent down to our map component
once we get that current location inside of map.
We can then use that current location to update what the map is centred upon now at present all of our
code around handling location updates is directly inside of our track.
Great screen if we left all of that code inside there.
So I'm talking specifically about this like permission stuff in this watch position stuff.
We could definitely leave the stuff inside of track create screen.
However if we did track track create screen with very quickly be very challenging to read.
So instead we're going to start to extract some of that logic into a new reusable hook called use location
anytime that we want to get some updates on a user's location or any time we want to read a user's location
in any way we're going to use this hook right here.
And we're going to pass it a callback function this callback function is going to be automatically invoked
by use location.
Anytime that the user's location changes.
So essentially the callback is going to be put in like right there.
Anytime we get an update on the user's location will invoke that callback so inside of track create
screen we can pass that callback over and inside of the callback we can get the most recent location
and use that to update the user's current location up inside of our provider and added onto the list
of locations that the user has passed through if they are currently recording a track.
OK.
I know this is all kind of complicated stuff but this is pretty much new it's what react native is there's
some degree of complicated stuff here and it's kind of unavoidable.
So now that we've got a better idea of what's going on.
Let's take one more quick pause start writing some code to implement all this stuff in the next video.