1 00:00:01,020 --> 00:00:05,580 Well we can draw to a series of points on our map which is definitely great but of course we probably 2 00:00:05,580 --> 00:00:07,800 won't show the user's actual location. 3 00:00:07,830 --> 00:00:11,790 So in this video we're going to start to get a better idea of how to figure out the user's current location 4 00:00:11,820 --> 00:00:15,030 in the world and then eventually show it on our map. 5 00:00:15,030 --> 00:00:18,720 Let's first begin with a quick discussion about a library that we're going to use to handle all this 6 00:00:18,720 --> 00:00:19,520 location stuff. 7 00:00:20,130 --> 00:00:23,730 So we're going to use a library called Expo dash location. 8 00:00:23,730 --> 00:00:28,200 Now unlike some the other libraries that we've used from Expo throughout this course Expo location is 9 00:00:28,200 --> 00:00:30,710 not installed inside of our project by default. 10 00:00:30,750 --> 00:00:35,550 So we do need to make sure that we install it separately a couple notes here on how we're going to use 11 00:00:35,550 --> 00:00:39,050 this library before we can ever actually track the user's location in the world. 12 00:00:39,060 --> 00:00:41,200 We need to ask the user for permission. 13 00:00:41,250 --> 00:00:46,370 Now this is not just like kind of us being nice and saying hey we're going to try to track your location. 14 00:00:46,380 --> 00:00:52,020 No instead we're going to tell the operating system that the phone is running so either IOW or android 15 00:00:52,260 --> 00:00:58,030 that we intend to track the user's location when we do that the IOW device or Android device is going 16 00:00:58,030 --> 00:01:01,630 to prompt the user and say hey this application is trying to track your location. 17 00:01:01,650 --> 00:01:06,200 Do you approve it or reject it if a user rejects that tracking. 18 00:01:06,260 --> 00:01:08,750 Well we need to make sure that we handle that in some way. 19 00:01:08,750 --> 00:01:10,520 But if user approves it that's great. 20 00:01:10,520 --> 00:01:16,610 We can then start to track the user's location and we're good to go when we start tracking the user's 21 00:01:16,610 --> 00:01:18,740 location with Expo location. 22 00:01:18,740 --> 00:01:24,830 There's two different forms of tracking we can use either foreground or background foreground tracking 23 00:01:24,920 --> 00:01:29,390 is a reference to saying that we're going to track the user's location anytime our application is visible 24 00:01:29,420 --> 00:01:30,950 on the screen. 25 00:01:30,950 --> 00:01:34,830 The nice thing about foreground tracking is that it's really easy to set up and use. 26 00:01:35,000 --> 00:01:40,010 It just takes one or two lines of code background checking on the other hand allows us to track the 27 00:01:40,010 --> 00:01:46,610 user's location at all times even if the user is not actively using our application or even if the device 28 00:01:46,640 --> 00:01:48,470 is locked. 29 00:01:48,470 --> 00:01:53,450 Now the downside to background location is that it uses considerably more battery power because in general 30 00:01:53,450 --> 00:01:55,520 we're just tracking the user for longer. 31 00:01:56,300 --> 00:02:01,160 It's also a lot more complicated to set a background location tracking because it involves running some 32 00:02:01,160 --> 00:02:07,360 amount of javascript code when our application is not actually up on the screen so for our application 33 00:02:07,420 --> 00:02:12,430 we're going to initially focus on using foreground location tracking just because like I said a little 34 00:02:12,430 --> 00:02:13,710 bit easier to get started with. 35 00:02:13,780 --> 00:02:19,220 So we can get a better understanding of exactly what's going on now lasting one dimension is that we 36 00:02:19,220 --> 00:02:24,680 need to be very much aware of whenever we are tracking the user's location because it does use some 37 00:02:24,680 --> 00:02:26,860 amount of battery power. 38 00:02:26,900 --> 00:02:31,180 This is going to be very relevant for our application in particular let me tell you why. 39 00:02:31,580 --> 00:02:36,610 So when a user first comes to the track create screen we want to show the user's location in the world. 40 00:02:36,740 --> 00:02:42,410 So the instant they come to the screen we need to immediately start tracking their location even if 41 00:02:42,410 --> 00:02:45,110 they do not tap on that record button. 42 00:02:45,110 --> 00:02:48,950 Now the key there is that when the user comes to the screen yes we're going to start tracking them. 43 00:02:49,010 --> 00:02:54,200 But if the user navigates a way to like the account screen or the track list without hitting record 44 00:02:54,440 --> 00:02:59,510 we need to then make sure that we stop tracking their location because their user is not actively trying 45 00:02:59,510 --> 00:03:04,390 to recording things so there's no purpose to us burning some battery power. 46 00:03:04,400 --> 00:03:10,520 However if a user comes to the screen and then hits record and then navigates away we definitely do 47 00:03:10,520 --> 00:03:13,310 want to continue to track their location. 48 00:03:13,310 --> 00:03:16,400 So in other words there's going to be some different scenarios here that we need to think about very 49 00:03:16,400 --> 00:03:21,110 carefully and decide whenever a user navigates away from the screen whether or not we want to continue 50 00:03:21,110 --> 00:03:23,810 tracking their location all right. 51 00:03:23,870 --> 00:03:28,310 That's some high level things we need to be aware of as we go through this process before we take a 52 00:03:28,310 --> 00:03:28,730 break. 53 00:03:28,730 --> 00:03:33,530 We're going to install Expo location very quickly so at our terminal we're going to run this command 54 00:03:33,530 --> 00:03:35,090 to install the library. 55 00:03:35,230 --> 00:03:38,060 Now you'll notice that we're not using a classic npm install here. 56 00:03:38,060 --> 00:03:42,660 That's because the version of Expo location we get depends upon the version of React Native. 57 00:03:42,770 --> 00:03:44,780 And expo that we are using. 58 00:03:44,900 --> 00:03:50,720 So by installing Expo location with Expo CSI we're going to make sure that we get the correct version. 59 00:03:50,720 --> 00:03:50,930 All right. 60 00:03:50,930 --> 00:03:56,190 So I'll fall back on my terminal and inside my project directory I'll do it. 61 00:03:56,220 --> 00:04:03,950 MP exposed the ally install Expo location like so and that's pretty much it. 62 00:04:04,090 --> 00:04:05,660 I'm going to let this do its thing. 63 00:04:05,790 --> 00:04:09,630 When we come back the next video we're gonna start to wire up some code inside of our project to make 64 00:04:09,630 --> 00:04:12,900 sure that we can ask users for permission to track their location.