function h = geoplot(varargin)
%GEOPLOT Geographic plot 
%   GEOPLOT(lat,lon) plots a line in a geographic axes with vertices at 
%   the latitude-longitude locations in degrees specified by the vectors
%   lat and lon, where lat and lon are the same size.
%
%   GEOPLOT(lat,lon,LineSpec) uses a LineSpec to specify the line style,
%   marker symbol, and color for the line. GEOPLOT(lat,lon,'c+:'), for
%   example, plots a cyan dotted line with a plus at each vertex point.
%   GEOPLOT(lat,lon,'bd') plots a blue diamond at each point and does not
%   show connecting line segments. By default, GEOPLOT draws a solid line,
%   with no markers, using colors specified by the geoaxes ColorOrder
%   property.
%
%   GEOPLOT(lat1,lon1,...,latN,lonN) combines the plots specified by
%   several sets of latitudes and longitudes.
%
%   GEOPLOT(lat1,lon1,LineSpec1,...,latN,lonN,LineSpecN) combines the
%   plots specified by several sets of latitudes and longitudes, with a
%   separate LineSpec for each line.
%
%   For example, GEOPLOT(lat1,lon1,'y-',lat2,lon2,'go') plots two sets of 
%   latitudes and longitudes: a solid yellow line in the first case and
%   unconnected green circles in the second.
%
%   GEOPLOT(___,Name,Value) specifies line properties using one or more
%   Name,Value pair arguments. For example,
%
%        GEOPLOT(lat,lon,'LineWidth',2,'Color',[.6 0 0])
%
%   plots a dark red line with a width of 2 points.
%
%   GEOPLOT(gx,___) plots in the geographic axes specified by gx instead of
%   the current axes.
%
%   H = GEOPLOT(___) returns a column vector of Chart Line objects, one
%   object per plotted line. Use H to modify the properties of the objects
%   after they area created.
%
%   Example
%   -------
%   latSeattle = 47.62;
%   lonSeattle = -122.33;
%   latAnchorage =  61.20;
%   lonAnchorage = -149.9;
%   geoplot([latSeattle latAnchorage],[lonSeattle lonAnchorage],'g-*')
%
%   See also GEOAXES, GEOBASEMAP, GEOBUBBLE, GEOSCATTER, PLOT

% Copyright 2017-2018 The MathWorks, Inc.

    narginchk(1,inf)
    [gx, args, nargs] = axescheck(varargin{:});
    if ~isempty(gx) && ~isa(gx, 'matlab.graphics.axis.GeographicAxes')
        error(message('MATLAB:graphics:geoplot:AxesInput'))
    end
    
    % Throw an error if we encounter any of the following patterns:
    %
    %    geoplot(<numeric>)                geoplot(gx, <numeric>)
    %    geoplot(<numeric>, LineSpec)      geoplot(gx, <numeric>, LineSpec)
    %    geoplot(<numeric>, Name, Value)   geoplot(gx, <numeric>, Name, Value)
    %
    % plot (and polarplot) support syntaxes like these -- where the numeric
    % placeholder is Y (for plot) and R or Z (for polarplot) -- but there
    % is no geoplot counterpart. Both latitude and longitude are required
    % when calling geoplot.
    if nargs > 0
        % Check for lat.
        if ~isnumeric(args{1})
            validateattributes(args{1},{'numeric'},{},'','lat')
        end
        
        % Check for lon.
        if nargs == 1 || ~isnumeric(args{2})
            error(message('MATLAB:graphics:geoplot:LongitudeRequired'))
        end
        
        % Check that lat and lon are equal length.
        if numel(args{1}) ~= numel(args{2})
            error(message('MATLAB:graphics:geoplot:DataLengthMismatch','lon','lat'));
        end
        
        v = matlab.graphics.chart.internal.maps.GeographicDataValidator("variables");
        validateLatitude(v,args{1});
        validateLongitude(v,args{2});
    end
    
    try
        gx = matlab.graphics.internal.prepareCoordinateSystem( ...
            'matlab.graphics.axis.GeographicAxes', gx, @geoaxes);

        obj = plot(gx, args{:});
    catch e
        if strcmp(e.identifier,'MATLAB:plot:DataPairsMismatch')
            error(message('MATLAB:graphics:geoplot:DataPairsMismatch'))
        end
        throw(e)
    end
    
    if nargout > 0
        h = obj;
    end
end
