Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2016 17:34
Show Gist options
  • Save anonymous/42f0014496848a8600765596e2c1468a to your computer and use it in GitHub Desktop.
Save anonymous/42f0014496848a8600765596e2c1468a to your computer and use it in GitHub Desktop.
function Get-LongLat
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipelineByPropertyName = $true
)]
[string[]]$ZipCode
)
process
{
foreach($z in $ZipCode)
{
Write-Verbose "Getting geometry for $z"
$data = Invoke-RestMethod -Method Get -Uri "http://maps.googleapis.com/maps/api/geocode/json?address=$z"
$obj = [pscustomobject]@{
ZipCode = $z
Address = $data.results.formatted_address
Latitude = $data.results.geometry.location.lat
Longitude = $data.results.geometry.location.lng
}
Write-Output $obj
}
}
}
function Get-Forecast
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipelineByPropertyName = $true
)]
[string]$Latitude,
[Parameter(
Mandatory = $true,
ValueFromPipelineByPropertyName = $true
)]
[string]$Longitude,
[Parameter(
Mandatory = $false,
ValueFromPipelineByPropertyName = $true
)]
[string]$Apikey = 'myapikeyhere'
)
process
{
Write-Verbose "Getting forecast for $Latitude,$Longitude"
$data = Invoke-RestMethod -Method Get -Uri "https://api.forecast.io/forecast/$ApiKey/$Latitude,$Longitude"
Write-Output $data
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment