So, we'll go ahead and
add a location by address, just print out a little bit of debug at first.
And what we're fundamentally going to want to do is to call the geocoder
getLocationByAddress, but we don't know all the details yet of how that works.
So, let's us go over in finish implementing that.
So, I've got the shell of geocoder service that's going to call our back-end
locateByAdress, locateByPosition based upon inputs the caller is providing.
So, one of the fundamental things we need are the services that we're going to call,
the resources, and they are off of the APP_CONFIG.server_url and
go to the API/geocode/addresses.
That's what we just finished implementing in the previous lesson.
Now, as far as get it by address,
we just need to call the address as resource, with a get, and to pass
in a query argument of address with a string provided to us by our caller.
And, of course, we owe our caller a result and that'll be a proxy object and
it'll eventually get filled in with the data.
But until it's filled in,
there will be a dollar promise available off of what's getting returned.
And then, for the get by position, we just need to call the positions resource
with a get and we want to pass in a longitude and latitude, which is pretty
much what we're asking to be passed in but all we really care is that there's
a longitude and latitude property, whatever implements the position.
And as with by address we want to return a result.
And again, the result is a proxy that will eventually,
the data will get filled in as the response is returned.
But until it gets filled in, there will be a dollar promise that we can listen to.
Okay, that looks pretty much it for the geocoder service.
Wasn't much to it.
It was kind of easy.
So, if we go back to our location by address, all right,
the details that we're missing is that we could just assign it to location and
then when it does get completed, that location value will be filled in.
However, we want to do a little bit more.
We want to do some behavior when it gets resolved.
So, let's look at the dollar promise.
And implement a call back.
And let's have this call back go ahead and assign the result to the location.
But also, what we want to do is extract the position out of the location and
assign that to the image.
This is what has the lat and the long.
And then, since it's early, let's go ahead and print some debug.
Okay, with that we should be able to get some activity.
If I refresh my display, come back in to my images, if I come in and
say 901 Pratt Street, Pratt in Baltimore, and then click away,
you notice that it went out and did a geocode to our service API.
Found out that the formatted address was really West Pratt Street and
it was in Maryland with a zip code in the United States, and
then this being the geocoded address of that position.
Now, to make things look a little bit more obvious, let's, I don't know,
let's go ahead and put it in South America and now the latitude
should go in the negative direction, okay?
So, we've gone down to negative latitude and we put it some place else, okay?
So, that's giving us a value at this point and time.
Okay, so I'm not saying it's the best user interface in the world,
but we're able to do is take a user from a typed in partial address,
go ahead and fully resolve that into a longitude and a latitude.
So, when they supply an image, they don't have to know everything.
I mean, obviously, we don't want them to have to know the longitude and
the latitude values.
Although sometimes, that's not so bad either.
Better user interfaces can be created, that's for sure.
Just some functionality here.