Example Webservice / API call- 4 GoogleMaps API services

In the following video I work through connecting for four separate APIs which are all under GoogleMaps.  It is very easy to connect to them with AutoHotkey.  Simply get your own token and then adapt the below code to your needs!

Video reviewing the four GoogleMaps APIs.

AutoHotkey Merchandise-White Stress ball

GoogleMaps Directions API

;~  https://developers.google.com/maps/documentation/directions/
IniRead, API_Key,Auth.ini,API,Key ;read current token
queryString:=QueryString_Builder({"origin":"75 9th Ave New York, NY","destination":"MetLife Stadium 1 MetLife Stadium Dr East Rutherford, NJ 07073","key":API_Key})

Endpoint:="https://maps.googleapis.com/maps/api/directions/" . "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(Response)
;~  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
}

GoogleMaps GeoCode API

;~  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
}

GoogleMaps Places

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 "?"):("&")) key "=" value
return queryString
}

GoogleMaps TimeZone

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

 

Comments are closed.