www.gusucode.com > map 案例源码 matlab代码程序 > map/ReadAndDisplayARouteExample.m

    %% Read and Display a Route
% Read and display a route from Boston Logan International Airport to
% Mathworks in Natick, MA.
%%
% Read the route information from the GPX file.

% Copyright 2015 The MathWorks, Inc.

route = gpxread('sample_route');
%%
% Compute |latlim| and |lonlim| with a 0.05 buffer. 
[latlim, lonlim] = geoquadline(route.Latitude, route.Longitude);
[latlim, lonlim] = bufgeoquad(latlim, lonlim, .05, .05);
%%
% Display the route.
fig = figure;
pos = fig.Position;
fig.Position = [300 300 1.25*pos(3) 1.25*pos(4)];
ax = usamap(latlim, lonlim);
setm(ax, 'MLabelParallel', 43.5)
geoshow(route.Latitude, route.Longitude)
%%
% Extract the elements of route that include descriptions of turns, mark
% and color code each turn on the map, and construct a legend that displays
% the descriptions. Reverse the order, so that the legend displays the
% first turn at the top and the last at the bottom.
turns = route(~cellfun(@isempty, route.Description));
turns = turns(end:-1:1);
n = length(turns);
colors = cool(n);
for k=1:n
   geoshow(turns(k).Latitude, turns(k).Longitude, ...
       'DisplayType','point','MarkerEdgeColor',colors(k,:),...
       'Tag','turn','DisplayName',turns(k).Description)
end
legend(findobj(ax,'Tag','turn'),'Location','SouthOutside')