Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Google Maps Geolocation RequestDemonstrates how make a Google Maps Geolocation REST API request.
integer li_rc oleobject loo_Rest integer li_BTls integer li_Port integer li_BAutoReconnect integer li_Success oleobject loo_Json oleobject loo_ACellTowers oleobject loo_OCellTower oleobject loo_AWifi oleobject loo_OPoint string ls_ResponseJson oleobject loo_JsonResp oleobject loo_JsonLoc string ls_Latitude string ls_Longitude string ls_Accuracy // This example duplicates the following CURL request: // curl -d @your_filename.json -H "Content-Type: application/json" -i "https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY" // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Rest = create oleobject // Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest") if li_rc < 0 then destroy loo_Rest MessageBox("Error","Connecting to COM object failed") return end if // Connect to the Google API REST server. li_BTls = 1 li_Port = 443 li_BAutoReconnect = 1 li_Success = loo_Rest.Connect("www.googleapis.com",li_Port,li_BTls,li_BAutoReconnect) // Add the Content-Type request header. loo_Rest.AddHeader("Content-Type","application/json") // Add your API key as a query parameter loo_Rest.AddQueryParam("key","YOUR_API_KEY") // The JSON query is contained in the body of the HTTP POST. // This is a sample query (which we'll dynamically build in this example) // { // "homeMobileCountryCode": 310, // "homeMobileNetworkCode": 260, // "radioType": "gsm", // "carrier": "T-Mobile", // "cellTowers": [ // { // "cellId": 39627456, // "locationAreaCode": 40495, // "mobileCountryCode": 310, // "mobileNetworkCode": 260, // "age": 0, // "signalStrength": -95 // } // ], // "wifiAccessPoints": [ // { // "macAddress": "01:23:45:67:89:AB", // "signalStrength": 8, // "age": 0, // "signalToNoiseRatio": -65, // "channel": 8 // }, // { // "macAddress": "01:23:45:67:89:AC", // "signalStrength": 4, // "age": 0 // } // ] // } loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.AppendInt("homeMobileCountryCode",310) loo_Json.AppendInt("homeMobileNetworkCode",260) loo_Json.AppendString("radioType","gsm") loo_Json.AppendString("carrier","T-Mobile") loo_ACellTowers = loo_Json.AppendArray("cellTowers") loo_ACellTowers.AddObjectAt(0) loo_OCellTower = loo_ACellTowers.ObjectAt(0) loo_OCellTower.AppendInt("cellId",39627456) loo_OCellTower.AppendInt("locationAreaCode",40495) loo_OCellTower.AppendInt("mobileCountryCode",310) loo_OCellTower.AppendInt("mobileNetworkCode",260) loo_OCellTower.AppendInt("age",0) loo_OCellTower.AppendInt("signalStrength",-95) destroy loo_OCellTower destroy loo_ACellTowers loo_AWifi = loo_Json.AppendArray("wifiAccessPoints") loo_AWifi.AddObjectAt(0) loo_OPoint = loo_AWifi.ObjectAt(0) loo_OPoint.AppendString("macAddress","01:23:45:67:89:AB") loo_OPoint.AppendInt("signalStrength",8) loo_OPoint.AppendInt("age",0) loo_OPoint.AppendInt("signalToNoiseRatio",-65) loo_OPoint.AppendInt("channel",8) destroy loo_OPoint loo_AWifi.AddObjectAt(1) loo_OPoint = loo_AWifi.ObjectAt(1) loo_OPoint.AppendString("macAddress","01:23:45:67:89:AC") loo_OPoint.AppendInt("signalStrength",4) loo_OPoint.AppendInt("age",0) destroy loo_OPoint destroy loo_AWifi ls_ResponseJson = loo_Rest.FullRequestString("POST","/geolocation/v1/geolocate",loo_Json.Emit()) if loo_Rest.LastMethodSuccess <> 1 then Write-Debug loo_Rest.LastErrorText destroy loo_Rest destroy loo_Json return end if // When successful, the response code is 200. if loo_Rest.ResponseStatusCode <> 200 then // Examine the request/response to see what happened. Write-Debug "response status code = " + string(loo_Rest.ResponseStatusCode) Write-Debug "response status text = " + loo_Rest.ResponseStatusText Write-Debug "response header: " + loo_Rest.ResponseHeader Write-Debug "response JSON: " + ls_ResponseJson Write-Debug "---" Write-Debug "LastRequestStartLine: " + loo_Rest.LastRequestStartLine Write-Debug "LastRequestHeader: " + loo_Rest.LastRequestHeader destroy loo_Rest destroy loo_Json return end if loo_Json.EmitCompact = 0 Write-Debug "JSON request body: " + loo_Json.Emit() // The JSON response should look like this: // { // "location": { // "lat": 37.4248297, // "lng": -122.07346549999998 // }, // "accuracy": 1145.0 // } Write-Debug "JSON response: " + ls_ResponseJson loo_JsonResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonResp.ConnectToNewObject("Chilkat.JsonObject") loo_JsonResp.Load(ls_ResponseJson) loo_JsonLoc = loo_JsonResp.ObjectOf("location") // Any JSON value can be obtained as a string.. ls_Latitude = loo_JsonLoc.StringOf("lat") Write-Debug "latitude = " + ls_Latitude ls_Longitude = loo_JsonLoc.StringOf("lng") Write-Debug "longitude = " + ls_Longitude destroy loo_JsonLoc ls_Accuracy = loo_JsonResp.StringOf("accuracy") Write-Debug "accuracy = " + ls_Accuracy destroy loo_Rest destroy loo_Json destroy loo_JsonResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.