public/helper/Get-TwitterTrends_Closest.ps1

function Get-TwitterTrends_Closest {
<#
.SYNOPSIS
    Get locations with trending topics

.DESCRIPTION
    GET trends/closest
    
    Returns the locations that Twitter has trending topic information for, closest to a specified location.
    
    The response is an array of "locations" that encode the location's WOEID and some other human-readable information such as a canonical name and country the location belongs in.
    
    A WOEID is a Yahoo! Where On Earth ID.

.PARAMETER lat
    If provided with a long parameter the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude is -180.0 to +180.0 (West is negative, East is positive) inclusive.

.PARAMETER long
    If provided with a lat parameter the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude is -180.0 to +180.0 (West is negative, East is positive) inclusive.

.NOTES
    This helper function was generated by the information provided here:
    https://developer.twitter.com/en/docs/trends/locations-with-trending-topics/api-reference/get-trends-closest

#>

    [CmdletBinding()]
    Param(
        [string]$lat,
        [string]$long
    )
    Begin {

        [hashtable]$Parameters = $PSBoundParameters
                   $CmdletBindingParameters | ForEach-Object { $Parameters.Remove($_) }

        [string]$Method      = 'GET'
        [string]$Resource    = '/trends/closest'
        [string]$ResourceUrl = 'https://api.twitter.com/1.1/trends/closest.json'

    }
    Process {

        # Find & Replace any ResourceUrl parameters.
        $UrlParameters = [regex]::Matches($ResourceUrl, '(?<!\w):\w+')
        ForEach ($UrlParameter in $UrlParameters) {
            $UrlParameterValue = $Parameters["$($UrlParameter.Value.TrimStart(":"))"]
            $ResourceUrl = $ResourceUrl -Replace $UrlParameter.Value, $UrlParameterValue
        }

        $OAuthSettings = Get-TwitterOAuthSettings -Resource $Resource
        Invoke-TwitterAPI -Method $Method -ResourceUrl $ResourceUrl -Parameters $Parameters -OAuthSettings $OAuthSettings

    }
    End {

    }
}