void DistanceMercatorFunc::Execute(wxSQLite3FunctionContext& ctx)
{
    if ( ctx.GetArgCount() != 4 )
    {
        ctx.SetResultError(_T("Function takes exactly 4 arguments."));
        return;
    }
    double lat0 = ctx.GetDouble(0);
    double lon0 = ctx.GetDouble(1);
    double lat1 = ctx.GetDouble(2);
    double lon1 = ctx.GetDouble(3);
    if ( lat0 > 90. || lat0 < -90. || lat1 > 90. || lat1 < -90.)
    {
        ctx.SetResultError(_T("Latitude must be between -90 and 90."));
        return;
    }
    
    if ( lon0 > 180. || lon0 < -180. || lon1 > 180. || lon1 < -180.)
    {
        ctx.SetResultError(_T("Longitude must be between -180 and 180."));
        return;
    }
    
    double dist;
    DistanceBearingMercator_Plugin(lat0, lon0, lat1, lon1, NULL, &dist);
    
    ctx.SetResult(dist);
}