%% Plot the Tracks of Two Vehicles
% Plot multiple routes simultaneously in a geographic player. First, assign each route a unique identifier. Then, when plotting points on the routes using the plotPosition object function, specify the route identifier using the 'TrackID' name-value pair argument. In this example, the routes are labeled Vehicle 1 and Vehicle 2. This screen capture shows the point where the two routes are about to cross paths.
%
% Load data for a route.

data = load('geoRoute.mat');

% Extract data for the first vehicle.

lat1 = data.latitude;
lon1 = data.longitude;

% Create a synthetic route for the second vehicle that drives the same route in the opposite direction.

lat2 = flipud(lat1);
lon2 = flipud(lon1);

% Create a geoplayer object. Initialize the player to display the last 10 positions as a line trailing the current position.

zoomLevel = 12;
player = geoplayer(lat1(1),lon1(1),zoomLevel,...
    'HistoryDepth',10,'HistoryStyle','line');

% Plot the positions of both vehicles as they move over the route. Specify an ID for each track by using the 'TrackID' name-value pair argument. By default, the geoplayer object centers the display of the vehicle on the first track. You can center the display on other tracks by using the CenterOnID property of the geoplayer object.

loopCounter = length(lat1);
for i = 1:loopCounter
     plotPosition(player,lat1(i),lon1(i),'TrackID',1,'Label','Vehicle 1');
     plotPosition(player,lat2(i),lon2(i),'TrackID',2,'Label','Vehicle 2');
end

% Copyright 2019 The MathWorks, Inc.