>> Hey, Friends! It's Scott Hanselman
and it's another episode of Azure Friday.
I'm continuing my in-depth look at
the Azure Maps API and here I've got
Ricky Brandreth and we're going to talk about
the directions API and what you can do with routing.
>> Yes. So, the Azure maps, that platform,
we have a rest service which does
direction API and it allows
you to calculate directions either for a car,
or a truck, or a taxi,
walking, and several other modes
of transportation as well.
But it also allows you to do
it between multiple waypoints.
So, typically we go from point A to point B,
but we allow up to 50 waypoints,
so you can go from point A to Point B all the
way up to point AX.
>> Wow, that makes a lot of sense because
ordinarily when you use a public map,
I think about, I mean, they're walking,
or I'm on the train, or I'm driving.
But if I'm going to be doing an enterprise application,
I might be running a fleet,
I might have to do all kinds of
complicated routing to make
sure that I do the most efficient thing.
So, it makes sense that I
would have that kind of control.
>> Exactly. And even go more into that.
We also support the waypoint optimization.
So, you might put your waypoints in ABCD,
but that might not be
the most efficient way to go between them.
And so, you can use
the Traveling Salesman algorithm which
we know from university.
It's already built in, you just simply say,
optimize my waypoints, and it will do it for you.
>> And then, Azure Maps in the APIs handle it for me?
>> Yes.
>> Very cool, and you have some demos for me?
>> Yes, and so, one other thing what's
pretty neat is you can also calculate
routes based on your combustion or electric efficiency.
>> No way.
>> So, if you have an electric car,
you can put in how much Kilojoules
you have left in your car,
and it'll try to give you the best route for that,
so that you can make it to your destination.
>> That's interesting and that's
a really complicated stuff.
I mean, there's a lot of
things that one could potentially,
I don't know if Azure Maps does this,
but when you're thinking about efficiency,
there's the wind direction at the time,
and there's topography, by going
up hills or downhill, and all that kind of stuff.
>> Yeah, and you can also take into
consideration departure and arrival times.
So, if you need to be at a place for a certain time,
you can put that into the request and it'll say,
"Okay, you need to leave by this time."
And if you need to, or
if you're departing at a certain time,
we'll tell you approximately when you all arrive.
It uses traffic data for that to make sure that
it will use real time traffic data
if you do the calculation right now.
It also uses historical traffic,
if we put in a previous date.
If you put in a future date,
it will actually use predictive,
using that historical data.
>> Wow, that's pretty cool.
And what's great about this, of course,
is that this all lives in my Azure account.
I can sign up and set up Azure Maps in the Azure portal,
and I can put this into My Applications today.
>> Yes, exactly.
>> What do you got to show me?
>> So, yeah this was
just a brief overview
of some of the things we just talked about.
But, what also I wanted to highlight,
was that we have routing and the directions
API's available in 116 countries around the globe.
>> That is a lot.
Almost all of them. That's great.
>> Yeah, it's pretty good coverage there.
So, now I want to jump into a demo
here and just taking a look at a simple rest request.
So, we're looking here in Postman and we
have our simple URL put into the service.
We want to place on request and
we're using the version one of the API,
you pass in your subscription key which
is that jumbled up string there,
and then your queries, your query is your waypoints.
So, in this case, you're breezing
coordinates that are delimited.
So, we have two coordinates in this request.
I've also requested that the polylines,
or the route path be
returned so that we can use it for rendering later.
>> Nice. Okay.
>> And then I've also
specified my travel mode
which in this case is set to car.
>> I assume that even though I'm passing
in latitude and longitude from point A to Point B,
I could pass in other points and things like that.
>> Correct.
So, if we just take a quick look at
the response that comes back.
One of the first things you see is the summary,
and it provides us some pretty useful information,
and the first one being the actual length
of the route in meters,
and also the travel time in seconds.
It also tells us the traffic delay in seconds as well.
So, how much of that time,
of that travel time, is due to traffic.
We also see the departure time and
the arrival time that are
estimated based on when you made the request.
Then, if we jump in further,
we can also see all the
coordinates that make up that route path.
>> Okay. So, those are
the points that make the polyline that it returned.
>> Correct.
>> Very cool. And I can render
that like you said, however I want to?
>> Yeah. Yes, you have
full control over how it's rendered.
Then, if we take a look at this other request,
so this request here's the same request with one minor,
addition as we install,
added the request to add a return instructions.
So, by default, we'll return the line,
but you can return the
instructions in a lot of different ways.
You can get just a readable text,
which is human readable,
you can get returned in a coded format which is better
for programmatic understanding of
the stuff you want to turn by turn.
Then, there's also the ability to have
an enhanced text version essentially which will
have some XML markup around certain keywords,
so that if you want to go through it and
maybe highlight it and things like that.
>> Or text or voice?
>> Yeah.
>> Yeah. So, instruction types text.
That means like turn left on
Main Street and things like that.
>> So, this same request that we just did before,
but now with the instructions being returned,
if we scroll down here, we'll see that-
>> Did you say that one?
>> Yeah.
>> Keep right.
Yeah, look at that, it's just plain English.
>> It's just plain English,
easy to understand, gives us a lot of useful information,
like what's the actual street name,
any sign post information,
what kind of junction type is it.
So, this is a bifurcation which
is essentially the intersection of two highways,
and then the other information like keep right,
and things like that. So, real simple thing.
>> It's cool. So, for myself as someone
of course uses GPS instructions all the time,
there's also hidden information
that I wish they would tell me,
that I could then add to my application,
turn angle in degrees.
It's a 45 degree angle,
and the bifurcation where
the street is going to split into two.
There's a lot of cool stuff information that I
could integrate into my app if I chose to.
>> Exactly. So, moving on.
I've wanted to show a couple of looking at JSON's grape,
it's better to look at the actual routes on a map.
>> Absolutely.
>> So, this example here
shows a car versus truck routing.
Trucks can't go everywhere that a car can go,
and for various reasons,
there's the size of the truck,
you can't make tight turns,
can't go under little bridges.
Sometimes trucks are carrying hazardous materials
and they can't go in certain places like tunnels.
So, let's take a quick look at a couple examples.
So, this is one example here.
The red line indicates where a car would normally go,
which is a nice short path and direct path.
But the green line
indicates the route the truck has to go,
and the main reason for the difference is
right here at this intersection here.
There's actually a low bridge.
Then, similarly, if we take a look
at this road here, again,
we see the red orange being
car route and the green one being the truck route.
This little intersection right there
is not really tight
turns or too tight for the truck to turn.
>> Which is funny that you mention all of this
because just on Twitter a couple of days ago,
there was a picture of a truck trying to go underneath
an overpass and it took the entire,
sheared off the top and it
dropped like soybeans all over the path.
That is why we need
this kind of good information
in our commercial applications.
>> This happens daily where
trucks are just taking the same road as the car,
and if they used a service like this,
they would know ahead of
time that they need to take a different route.
>> One other really interesting one is flammable load,
so maybe you're driving a taco truck,
and you got some really spicy goods in there.
So, it's really flammable.
So, you can't go through
the Liberty tunnel because we cannot.
We should never take tacos in the Liberty tunnel.
>> Same thing with the INID here in Seattle.
You can't take flammable goods on there as well.
So, if we will look at the Liberty tunnel here,
we can see that you have to take a route that's
nearly twice as long to get to your destination.
>> But, that kind of stuff really matters,
and that's important, why
that the fact that this is available,
that Azure Maps is available as an API
that's built into the Azure portal for developers to go,
and integrate into their fleet management applications
or their enterprise apps.
>> So, next time I
wanted to show is the waypoint optimization.
So, here we have a whole bunch of points on the map,
and if we were to simply calculate
the route between them,
we can see we get this pretty intense route
in the- if we scroll down a little bit.
>> So, that's just in the order
that the person threw them in there?
>> Right. So, the total distance
is about 144 kilometers to
do all this route
in the order that the pins were provided.
Now, if we do that same thing but
we turn on the optimization,
we're nearly 50 kilometers shorter on
the route and it looks
a lot cleaner as well when you look ahead on the map.
>> Okay. So, you're starting at Pin0.
>> Yeah, and we're going from zero to five to one to two,
the forward and so on.
>> Cutting it by 30-plus percent.
>> Correct.
>> Saving money, saving gas, saving time.
>> Correct.
>> That's fantastic, and all of this stuff is
available in the Azure Maps API,
we can go and sign up in the Azure portal,
and start integrating this today.
>> Correct.
>> Fantastic. I am learning
all about the complexities of routing,
and finally getting able to use
the Traveling Salesman algorithm after university,
today on Azure Friday.