1
00:00:02,310 --> 00:00:05,180
So we added this get coords from address function,

2
00:00:05,190 --> 00:00:07,290
let's now use it in share place,

3
00:00:07,290 --> 00:00:10,930
there when we have the address entered by the user,

4
00:00:11,010 --> 00:00:14,030
I want to try to convert to coordinates.

5
00:00:14,160 --> 00:00:24,040
So for that, let's import this function we just created from ./utility/location

6
00:00:24,280 --> 00:00:32,410
and the function name was get coords from address. Now let's call this function in the find address handler

7
00:00:32,410 --> 00:00:40,010
method, get coords from address, and forward that address which we retrieved here from the user input.

8
00:00:40,030 --> 00:00:43,330
Now this will return a promise because we're using async await in there

9
00:00:43,330 --> 00:00:48,680
and as you learned, the entire function which you use async await in will return a promise.

10
00:00:48,700 --> 00:00:55,960
So we should add then here to actually get the response or what I will do, use async await on this method

11
00:00:55,960 --> 00:01:01,300
as well, you can use async await there as well because in the end it's just a normal function, just being

12
00:01:01,300 --> 00:01:04,600
part of a class, we can add the async keyword here

13
00:01:04,600 --> 00:01:13,160
so that here in front of get coords from address, we can await instead of using then and catch. Now we'll

14
00:01:13,160 --> 00:01:18,230
get these coordinates here ultimately and we can store this in a constant so that thereafter we can

15
00:01:18,230 --> 00:01:25,040
call this select place and forward the coordinates and we'll forward coordinates in exactly the same format

16
00:01:25,220 --> 00:01:28,290
we would get them if we auto locate the user.

17
00:01:28,460 --> 00:01:33,380
Now of course this might fail though, we're throwing a couple of errors in here after all if certain

18
00:01:33,380 --> 00:01:40,340
things go wrong, so we should also wrap this into try catch, if you're not using async await you would

19
00:01:40,340 --> 00:01:46,970
use a catch block simply and catch any potential errors we might be getting here so that we can simply

20
00:01:46,970 --> 00:01:52,940
throw an alert where we display the error message, the built-in error a constructor function gives you

21
00:01:52,940 --> 00:01:58,970
an object which has a message property where this message you're passing in here to the constructor

22
00:01:58,970 --> 00:02:03,570
will be stored in, so I can display these messages to the user in an alert

23
00:02:03,580 --> 00:02:10,460
now if something fails here, otherwise we should hopefully get the coordinates and display them and thereafter

24
00:02:10,460 --> 00:02:12,000
I'll call modal hide,

25
00:02:12,050 --> 00:02:15,370
this is not getting executed right away because we have await in there.

26
00:02:15,440 --> 00:02:20,630
So since we have await in there, we'll wait for it to finish before the other lines execute because

27
00:02:20,630 --> 00:02:26,570
all the other lines thereafter as you learned are in the end just wrapped into an invisible then block

28
00:02:26,690 --> 00:02:34,310
because we just use promises here, just invisibly convert it from then and catch to await and try catch.

29
00:02:35,960 --> 00:02:40,860
So lots of work, let's save that and let's give it a try, here

30
00:02:40,880 --> 00:02:48,920
let's enter a street like 6th Avenue and click on find place and we get the spinner and if everything

31
00:02:48,920 --> 00:02:55,040
works correctly, you should get this output here where the marker is somewhere in 6th Avenue and of course

32
00:02:55,040 --> 00:03:00,260
you could enter a more detailed address here, your own address maybe to see whether that works as well. You

33
00:03:00,260 --> 00:03:06,110
can also write New York here and Google really does its best to locate this and find the right location.

34
00:03:06,910 --> 00:03:12,390
So with that, we get this functionality added as well, now as a next step,

35
00:03:12,470 --> 00:03:19,370
I want to make sure that based on this, we now always get an address even if we auto locate the user

36
00:03:19,460 --> 00:03:23,840
which we're currently not doing, we're not getting an address for that and that we then show a shareable

37
00:03:23,840 --> 00:03:26,780
link here which we can use to

38
00:03:26,940 --> 00:03:33,320
in the end open this page here and start on such a map with the marker placed in there.
