1 00:00:01,090 --> 00:00:04,200 We just put together some amount of code to fake the user's location. 2 00:00:04,210 --> 00:00:07,480 Now one thing on mentioned very quickly is that you're not going to find any reference to this stuff 3 00:00:07,480 --> 00:00:09,370 inside the expo documentation. 4 00:00:09,370 --> 00:00:14,440 I just went through the source code found out how we actually change or Expo itself changes the user's 5 00:00:14,440 --> 00:00:15,700 location and saw. 6 00:00:15,790 --> 00:00:17,330 This is pretty much how they do it. 7 00:00:17,350 --> 00:00:22,120 So not going to see this in the documentation just a little trick that is going to be very handy for 8 00:00:22,120 --> 00:00:24,290 us to test out our application. 9 00:00:24,290 --> 00:00:24,490 OK. 10 00:00:24,530 --> 00:00:27,130 Now we've got all this fake location stuff put together. 11 00:00:27,130 --> 00:00:31,780 We're gonna go back over to our track create screen and actually try to watch the user's location change 12 00:00:31,810 --> 00:00:36,970 over time so to get started we're gonna find our import statement from Expo location and we're going 13 00:00:36,970 --> 00:00:43,390 to import a second function here called Watch position async and then we're going to import something 14 00:00:43,390 --> 00:00:45,070 else called accuracy 15 00:00:47,880 --> 00:00:53,700 then right after we do our permissions request right here we're going to add in an a wait watch position 16 00:00:53,820 --> 00:00:59,560 async so as you might guess this is going to watch the user's location and see it change over time. 17 00:00:59,640 --> 00:01:04,440 The first argument is this function is going to be an options object inside of here we're going to define 18 00:01:04,440 --> 00:01:11,700 an option of accuracy or accuracy is essentially how accurate we want our location reading to be. 19 00:01:11,910 --> 00:01:19,020 We can go anywhere from a accuracy of like one to five kilometres all the way down to a like meter accuracy 20 00:01:19,590 --> 00:01:24,390 the higher accuracy we asked for the more battery power it's going to take because our application is 21 00:01:24,390 --> 00:01:29,370 all about watching the user's location and seeing it change over time and the user very possibly might 22 00:01:29,370 --> 00:01:32,210 be like on foot or on a bike or something like that. 23 00:01:32,340 --> 00:01:37,170 We probably want to have some very high accuracy so for accuracy right here I'm going to say accuracy 24 00:01:37,170 --> 00:01:40,020 dot best for navigation. 25 00:01:40,050 --> 00:01:47,260 Like so that means give us some very high accuracy in these readings after that we're gonna put in a 26 00:01:47,320 --> 00:01:54,300 time interval that means 1000 right there that means that we want to try to get an update once every 27 00:01:54,300 --> 00:01:55,350 second. 28 00:01:55,680 --> 00:02:01,710 We'll also put in a distance interval of 10 and that means that we should also try to get an update 29 00:02:01,740 --> 00:02:03,420 once every 10 meters. 30 00:02:03,420 --> 00:02:10,750 So either once every second or once every 10 meters one or the other now is the second argument to watch 31 00:02:10,750 --> 00:02:15,940 position async we're gonna put in a callback function so this callback function right here is going 32 00:02:15,940 --> 00:02:20,470 to take some location object from the expo location library. 33 00:02:20,500 --> 00:02:24,160 So this object right here describes the user's actual location. 34 00:02:24,160 --> 00:02:29,050 So right now I'll just do a simple council log of their location and I'm just gonna try to print it 35 00:02:29,050 --> 00:02:31,530 out at the terminal OK. 36 00:02:31,570 --> 00:02:32,770 So that's pretty much it. 37 00:02:32,770 --> 00:02:33,730 Now let's save this. 38 00:02:33,730 --> 00:02:37,140 We're gonna test it out and see how this stuff all works together. 39 00:02:37,240 --> 00:02:44,230 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 40 00:02:44,230 --> 00:02:49,810 terminal and once over there I should start to see a bunch of different console logs up here. 41 00:02:49,840 --> 00:02:52,910 Now you're going to notice that we get some very different console logs. 42 00:02:53,030 --> 00:02:57,430 Some of these have a timestamp of like whatever that is about 1 billion or so. 43 00:02:57,440 --> 00:03:00,410 So those are the fake locations that we are now triggering. 44 00:03:00,410 --> 00:03:06,410 Once per seconds you'll notice that I'm not really getting any console logs at all from the code that 45 00:03:06,410 --> 00:03:07,820 we just added in. 46 00:03:07,820 --> 00:03:11,530 Even though we kind of said right here that we wanted an update once every second. 47 00:03:11,540 --> 00:03:16,830 So once again Expo location as a package I've not found that it's the most stable thing around. 48 00:03:16,850 --> 00:03:21,180 So for whatever reason it's really just not giving me an update once every second. 49 00:03:21,230 --> 00:03:25,240 And that's why having this test location code we just put together is really handy. 50 00:03:25,310 --> 00:03:29,780 So no matter what while we are testing our application we know that we'll always get one update per 51 00:03:29,780 --> 00:03:32,560 second guess that looks good. 52 00:03:32,650 --> 00:03:34,600 Not gonna test this out on Android as well. 53 00:03:36,460 --> 00:03:38,160 So I'll bring up my Android device. 54 00:03:38,180 --> 00:03:44,830 Go to try track create then if I flip back over once again I should see these kind of fake locations 55 00:03:45,130 --> 00:03:47,990 being emitted once every second here. 56 00:03:48,030 --> 00:03:48,890 So it looks pretty good. 57 00:03:48,890 --> 00:03:52,220 We've now got some fake blue date location data popping out here. 58 00:03:52,250 --> 00:03:57,380 So now we can start to track this information and use it to show the user's current spot on the map 59 00:03:57,860 --> 00:04:02,560 and then eventually record this information and draw it on the map as a line as well. 60 00:04:02,660 --> 00:04:04,610 So a quick pause and I'll see you in just a minute.