So we added this get coords from address function,
let's now use it in share place,
there when we have the address entered by the user,
I want to try to convert to coordinates.
So for that, let's import this function we just created from ./utility/location
and the function name was get coords from address. Now let's call this function in the find address handler
method, get coords from address, and forward that address which we retrieved here from the user input.
Now this will return a promise because we're using async await in there
and as you learned, the entire function which you use async await in will return a promise.
So we should add then here to actually get the response or what I will do, use async await on this method
as well, you can use async await there as well because in the end it's just a normal function, just being
part of a class, we can add the async keyword here
so that here in front of get coords from address, we can await instead of using then and catch. Now we'll
get these coordinates here ultimately and we can store this in a constant so that thereafter we can
call this select place and forward the coordinates and we'll forward coordinates in exactly the same format
we would get them if we auto locate the user.
Now of course this might fail though, we're throwing a couple of errors in here after all if certain
things go wrong, so we should also wrap this into try catch, if you're not using async await you would
use a catch block simply and catch any potential errors we might be getting here so that we can simply
throw an alert where we display the error message, the built-in error a constructor function gives you
an object which has a message property where this message you're passing in here to the constructor
will be stored in, so I can display these messages to the user in an alert
now if something fails here, otherwise we should hopefully get the coordinates and display them and thereafter
I'll call modal hide,
this is not getting executed right away because we have await in there.
So since we have await in there, we'll wait for it to finish before the other lines execute because
all the other lines thereafter as you learned are in the end just wrapped into an invisible then block
because we just use promises here, just invisibly convert it from then and catch to await and try catch.
So lots of work, let's save that and let's give it a try, here
let's enter a street like 6th Avenue and click on find place and we get the spinner and if everything
works correctly, you should get this output here where the marker is somewhere in 6th Avenue and of course
you could enter a more detailed address here, your own address maybe to see whether that works as well. You
can also write New York here and Google really does its best to locate this and find the right location.
So with that, we get this functionality added as well, now as a next step,
I want to make sure that based on this, we now always get an address even if we auto locate the user
which we're currently not doing, we're not getting an address for that and that we then show a shareable
link here which we can use to
in the end open this page here and start on such a map with the marker placed in there.