1
00:00:00,330 --> 00:00:06,750
So because you want to access the user's location you need to create value but of type fuse location

2
00:00:06,750 --> 00:00:08,000
provide that API.

3
00:00:08,070 --> 00:00:08,930
So what is this class.

4
00:00:08,940 --> 00:00:10,450
Let's go to the Android documentation.

5
00:00:10,450 --> 00:00:15,660
Any in here just enter this you are a developer that and dot com slash index that.

6
00:00:15,720 --> 00:00:16,800
TMF OK.

7
00:00:16,980 --> 00:00:24,270
So inside the search bar just typing here fused location provided API so it can actually give us this

8
00:00:24,540 --> 00:00:24,860
link.

9
00:00:24,870 --> 00:00:26,290
It says in Google said it's true.

10
00:00:26,330 --> 00:00:27,380
So just click on it.

11
00:00:28,320 --> 00:00:30,030
Let's wait a little bit here.

12
00:00:30,090 --> 00:00:30,950
So it's going up.

13
00:00:30,960 --> 00:00:35,250
Open this page for us to fuse location provide that API.

14
00:00:35,430 --> 00:00:39,440
So it says public interface views like kitchen pro-white API.

15
00:00:39,450 --> 00:00:42,110
So this is actually an interface right.

16
00:00:42,150 --> 00:00:46,800
The main entry point for interacting with diffused the location pro-white there.

17
00:00:47,040 --> 00:00:53,670
So we must have access to these actually use the location provide that API in order to access the user's

18
00:00:53,670 --> 00:00:54,420
location.

19
00:00:54,600 --> 00:00:56,640
Okay this is actually the main entry point.

20
00:00:56,640 --> 00:00:58,200
This is very important.

21
00:00:58,260 --> 00:01:04,470
The method must be used in conjunction with the Google API client so you can see this here it is familiar

22
00:01:04,470 --> 00:01:09,840
to you you already use this piece of code inside are actually the uncreate method in order to initialize

23
00:01:09,840 --> 00:01:12,550
our Google API client instance right.

24
00:01:12,630 --> 00:01:20,600
So you can see this here and now you can see it is constancy a key location change the key marked location.

25
00:01:20,610 --> 00:01:22,360
And let's actually look at these methods.

26
00:01:22,470 --> 00:01:28,800
For example this one pending glissade it says flushers any location is currently being patched and sends

27
00:01:28,800 --> 00:01:36,030
them to all registers and we have the location update it says returns the best most recent location.

28
00:01:36,030 --> 00:01:41,520
Currently available look at this if it here gets last location so we are going to use this method in

29
00:01:41,520 --> 00:01:46,220
order to access that user's location we have location availability here.

30
00:01:46,320 --> 00:01:51,690
So it is actually called returns the availability of location data right.

31
00:01:51,940 --> 00:01:53,450
And all these if it's.

32
00:01:53,550 --> 00:01:54,180
Right.

33
00:01:54,470 --> 00:01:58,480
And we can see that can actually give us some descriptions about these methods.

34
00:01:58,480 --> 00:02:04,590
So this is them for that we are going to use GET last location insets returns the best most recent location

35
00:02:04,620 --> 00:02:05,900
currently available.

36
00:02:05,970 --> 00:02:12,700
If a location is not available which should happen very rarely null will be returned.

37
00:02:12,860 --> 00:02:18,670
Okay the best accuracy available while respecting the location permissions will be returned.

38
00:02:18,660 --> 00:02:23,120
This provides a simplified way to get location.

39
00:02:23,130 --> 00:02:30,660
It is particularly well suited for applications that do not require an accurate location and that do

40
00:02:30,660 --> 00:02:36,310
not actually want to maintain extra logic for allocation updates updates.

41
00:02:36,690 --> 00:02:37,800
So that's enough.

42
00:02:37,800 --> 00:02:44,100
Let's actually go to our Android studio and inside the curly braces of this statement I can actually

43
00:02:44,100 --> 00:02:50,220
create a value of idea but of type fuse location provide that API and the name is going to be just the

44
00:02:50,220 --> 00:02:54,560
fuse location provide that API and puts an assignment operator here.

45
00:02:54,720 --> 00:02:58,840
So because the fuse location pro-white that API is an interface.

46
00:02:58,920 --> 00:03:04,210
This means that we cannot create an object by using the new keyboard.

47
00:03:04,420 --> 00:03:05,090
OK.

48
00:03:05,550 --> 00:03:06,820
So just typing here.

49
00:03:06,870 --> 00:03:10,920
Location services that fused.

50
00:03:10,950 --> 00:03:15,780
So I just need to put a capital F that fuse location API semi-colon.

51
00:03:15,930 --> 00:03:19,140
So now its going actually to give us the fuse location API.

52
00:03:19,140 --> 00:03:24,750
So now this variable holds that right the main entry port in order to actually access the user's location.

53
00:03:24,750 --> 00:03:28,000
So let me actually create a new line here so that you can see this value better.

54
00:03:28,320 --> 00:03:35,070
So now it's time to initialize our location rowdier but that we declared inside our main activity class.

55
00:03:35,070 --> 00:03:36,230
So let me scroll to the top.

56
00:03:36,270 --> 00:03:43,110
You can see this variable here location and we have not yet initialized this location very well so now

57
00:03:43,140 --> 00:03:44,090
it's time to do that.

58
00:03:44,100 --> 00:03:48,950
Let's actually scroll down here and let's go inside this show they use their location method after this

59
00:03:48,950 --> 00:03:51,950
line of code that actually gets the fuse the location API.

60
00:03:52,140 --> 00:03:58,170
I can just type in a location assignment operator and now I can get you to access I can refer to this

61
00:03:58,180 --> 00:04:03,090
fuse location provider IP or so just type in your fuse the location provider API and now we can call

62
00:04:03,090 --> 00:04:06,840
this method and this instance gets last location.

63
00:04:06,840 --> 00:04:07,300
Right.

64
00:04:07,500 --> 00:04:11,970
And as the argument we must pass the Google API client instance.

65
00:04:12,030 --> 00:04:13,780
So we already have that in a sense right.

66
00:04:13,780 --> 00:04:16,900
So just typing here Google API client instance semi-colon.

67
00:04:16,980 --> 00:04:21,420
So you know that we actually created this value but here in line number 23 inside our main activity

68
00:04:21,420 --> 00:04:24,090
class and the initialized this rally about here.

69
00:04:24,120 --> 00:04:27,680
So now we are we need to pass this value here.

70
00:04:27,720 --> 00:04:33,690
This will be the client here as the argument to the Smurfit So now it can actually give us the location

71
00:04:33,750 --> 00:04:35,770
if it is actually not null.

72
00:04:35,880 --> 00:04:37,990
So we need to actually check for that condition.

73
00:04:37,990 --> 00:04:40,690
So here it is called defensive programming.

74
00:04:40,710 --> 00:04:43,290
We must check for any conditions.

75
00:04:43,470 --> 00:04:44,860
Conditions may actually go wrong.

76
00:04:44,910 --> 00:04:48,010
OK the user may not be able to access the location.

77
00:04:48,030 --> 00:04:49,520
We must check for that condition.

78
00:04:49,530 --> 00:04:58,320
So I cant just create an if statement here I can say if location is not equal to non-HD OK that I open

79
00:04:58,620 --> 00:05:04,920
and close this if statement by using curly braces and open incredible is followed by a closing curly

80
00:05:04,920 --> 00:05:07,390
brace inside this statement.

81
00:05:07,620 --> 00:05:15,690
Now I am a hundred and fifty percent sure that this location here is not actually not because I am inside

82
00:05:15,690 --> 00:05:18,270
the curly braces of this statement right.

83
00:05:18,300 --> 00:05:24,100
So here I can say double here and the name of this variable is going to be letter.

84
00:05:24,130 --> 00:05:30,390
So I am actually creating a local variable of type double here latitudes assignment operator.

85
00:05:30,730 --> 00:05:37,420
And now because I have the location here this location actually holds the latitude and longitude coordinates.

86
00:05:37,420 --> 00:05:44,410
So here I can say location that latitude that gets latitude Senechal right and now I can say double

87
00:05:45,880 --> 00:05:46,750
longitude.

88
00:05:48,490 --> 00:05:55,520
Assignment operator location that gets longitude semicolon right.

89
00:05:55,690 --> 00:06:05,250
And now I can actually just type in here TXI the location that said text and insight Apprentice's here.

90
00:06:05,500 --> 00:06:07,710
I can just type in here.

91
00:06:07,830 --> 00:06:14,500
Actually latitude plus two coats and just put a comma here.

92
00:06:14,500 --> 00:06:17,220
Space plus longitude.

93
00:06:17,350 --> 00:06:23,880
So I want to actually outputs the latitude and longitude of the use user's location to the actually

94
00:06:24,010 --> 00:06:24,670
screen.

95
00:06:24,910 --> 00:06:30,940
OK so because we want to access the user's location it is necessary that you run your application on

96
00:06:30,940 --> 00:06:37,240
your actual Android device because the emulator does not have the capability to actually understand

97
00:06:37,240 --> 00:06:39,360
the user's location right.

98
00:06:39,460 --> 00:06:47,060
So here first let's also create an else statement for this if statement here.

99
00:06:47,200 --> 00:06:49,850
So here we are thinking that if the location is not equal to.

100
00:06:49,860 --> 00:06:50,470
All right.

101
00:06:50,560 --> 00:06:55,750
So what happens if the location is actually not in that case we can actually create an else statement

102
00:06:55,780 --> 00:06:58,780
and let the user know that the application.

103
00:06:58,840 --> 00:06:59,590
Would that be able.

104
00:06:59,620 --> 00:07:02,160
We would not be able to access the location now.

105
00:07:02,170 --> 00:07:11,510
So here I can say to the location that said text and instead of prentices I can say the app the app

106
00:07:12,940 --> 00:07:23,050
is not actually able to access the location the location.

107
00:07:23,230 --> 00:07:30,850
Now try again later try again later.

108
00:07:30,870 --> 00:07:38,070
So let me create a new line here so as you can see the idea I put this plus operator here is a concatenation

109
00:07:38,070 --> 00:07:41,070
operator in order to concatenate this value with this value.

110
00:07:41,070 --> 00:07:43,360
When I tried to actually create a new light.

111
00:07:43,370 --> 00:07:44,750
You're right.

112
00:07:44,790 --> 00:07:46,020
So that's it.

113
00:07:46,020 --> 00:07:51,660
So we need to actually also create some efforts it's we need to actually call the Smurfette from another

114
00:07:51,660 --> 00:07:53,450
location from other methods.

115
00:07:53,460 --> 00:07:58,170
So we just created this custom effect here and we are not calling it from other methods yet.

116
00:07:58,290 --> 00:07:59,940
So let's see how we can do that.

