-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch-GmapNearbyPlace.ps1
95 lines (90 loc) · 4.32 KB
/
Search-GmapNearbyPlace.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Function Search-GmapNearbyPlace
{
<#
.SYNOPSIS
This will send a text query and return an object of place information back.
.DESCRIPTION
This will send a text query and return an object of place information back.
Uses the Google Places API.
.EXAMPLE
Search-GmapNearbyPlace -Query "Pizza in New York"
This will send a text query of "Pizza in New York" to the Google Places textsearch API endpoint.
The object(s) returned will have information about the places found.
.EXAMPLE
Get-GmapGeoCode -Address "123 Main St, New York, NY" | Search-GmapNearbyPlace -Query "Pizza in New York" -Radius 250 -Verbose
First the Get-GmapGeoCode function is run for that adddress. The object returned (which has Latitude and Longitude property) is then piped to this function.
The Latitude and Longitude parameters require a Radius parameter, which was specified as 250. Which should find matches within 250 meters. The -Verbose parameter
is used to display the Write-Verbose messages. All of the functions in this module support the -Verbose parameter.
.NOTES
Requires an active Google Place API Key. This key should be set to the moduel variable `$GPlacesApiKey.
Refer to https://developers.google.com/places/web-service/intro
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True)]
$Query,
[Parameter(Mandatory=$False,
ValueFromPipelinebyPropertyName=$true,ParameterSetName="Location")]
$Latitude,
[Parameter(Mandatory=$False,
ValueFromPipelinebyPropertyName=$true,ParameterSetName="Location")]
$Longitude,
[Parameter(Mandatory=$True,ParameterSetName="Location")]
$Radius,
[Parameter(Mandatory=$False)]
$options
)
Begin{}
Process
{
If($PSCmdlet.ParameterSetName -eq "Location")
{
$Location = "$($Latitude),$($Longitude)"
Write-Verbose "Using location of $Location"
If($options)
{
$url = $BaseUri + 'place/textsearch/json?query=' + $Query + '&' + 'location=' + $Location + '&' + 'radius=' + $Radius + $(New-GmapQuery -ApiKey $GPlacesApiKey -options $options)
}
else
{
$url = $BaseUri + 'place/textsearch/json?query=' + $Query + '&' + 'location=' + $Location + '&' + 'radius=' + $Radius + $(New-GmapQuery -ApiKey $GPlacesApiKey)
}
Write-Verbose "Sending Url of $url"
$Results = Invoke-RestMethod -Uri $url # Refer to here https://developers.google.com/places/web-service/details for more info about returned properties
If($Results.status -eq 'OK')
{
$Results = $Results.results # get the results from json data returned from Google API
$Results | Format-GmapPlaceSearch # send it to function which adds ScriptProperties and ScriptMethods, sets Default Display Set
}
else
{
Write-Warning "Did not get succcessful return from Google API"
$Results
}
}
else
{
If($options)
{
$url = $BaseUri + 'place/textsearch/json?query=' + $Query + '&' + 'radius=' + $Radius + $(New-GmapQuery -ApiKey $GPlacesApiKey -options $options)
}
else
{
$url = $BaseUri + 'place/textsearch/json?query=' + $Query + '&' + 'radius=' + $Radius + $(New-GmapQuery -ApiKey $GPlacesApiKey)
}
Write-Verbose "Sending Url of $url"
$Results = Invoke-RestMethod -Uri $url # Refer to here https://developers.google.com/places/web-service/details for more info about returned properties
If($Results.status -eq 'OK')
{
$Results = $Results.results # get the results from json data returned from Google API
$Results | Format-GmapPlaceSearch # send it to function which adds ScriptProperties and ScriptMethods, sets Default Display Set
}
else
{
Write-Warning "Did not get succcessful return from Google API"
$Results
}
}
}
}