Skip to content

Instantly share code, notes, and snippets.

@JoeGlines
Created April 22, 2021 21:18
Show Gist options
  • Save JoeGlines/cee2c123018cf8afabadb099a670477c to your computer and use it in GitHub Desktop.
Save JoeGlines/cee2c123018cf8afabadb099a670477c to your computer and use it in GitHub Desktop.
;*******************************************************
; Want a clear path for learning AutoHotkey; Take a look at our AutoHotkey Udemy courses. They're structured in a way to make learning AHK EASY
; Right now you can get a coupon code here: https://the-Automator.com/Learn
;*******************************************************
;~ https://developers.google.com/maps/documentation/geocoding/start
IniRead, API_Key,Auth.ini,API,Key ;read current token
;~ queryString:=QueryString_Builder({"address":"836 Kilbridge Lane, Coppell, TX","key":API_Key})
queryString:=QueryString_Builder({"address":"1600 Amphitheatre Parkway, Mountain View, CA","key":API_Key})
Endpoint:="https://maps.googleapis.com/maps/api/geocode/" . "xml" ;xml or json
;***********API call*******************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . queryString) ; "GET" "POST" ; be sure to uppercase
HTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
HTTP.Send()
Response:=HTTP.ResponseText
SciTE_Output(sXML_Pretty(Response," ")) ;Text,Clear=1,LineBreak=1,Exit=0
;***********query string builder*******************
QueryString_Builder(kvp){
for key, value in kvp
queryString.=((A_Index="1")?(url "?"):("&")) key "=" value
return queryString
}</pre>
<h2>GoogleMaps Places</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="null">IniRead, API_Key,Auth.ini,API, Key ;read current token
Endpoint:="https://maps.googleapis.com/maps/api/place/nearbysearch/xml" ; json or xml
queryString:=QueryString_Builder({"location":"32.9939970,-96.9947992","radius":"1000","types":"food","key":API_Key})
API_Call(Endpoint,queryString)
;******************************
API_Call(Endpoint,queryString){
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . queryString )
HTTP.Send()
Response:=HTTP.ResponseText
SciTE_Output(Response) ;Text,Clear=1,LineBreak=1,Exit=0
}
;***********query string builder*******************
QueryString_Builder(kvp){
for key, value in kvp
queryString.=((A_Index="1")?(url "?"):("&amp;")) key "=" value
return queryString
}</pre>
<h2>GoogleMaps TimeZone</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="null">IniRead, API_Key,Auth.ini,API,Key ;read current token
;~ The following example requests the time zone data for Washington, DC, USA, on March 15, 2016, in JSON format:
queryString:=QueryString_Builder({"location":"38.908133,-77.047119","timestamp":"1458000000","key":API_Key}) ;location is lat/long tuple
Endpoint:="https://maps.googleapis.com/maps/api/timezone/" . "json" ;xml or json
;***********API call*******************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", Endpoint . queryString) ; "GET" "POST" ; be sure to uppercase
HTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
HTTP.Send()
Response:=HTTP.ResponseText
SciTE_Output(Response) ;Text,Clear=1,LineBreak=1,Exit=0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment