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
(DataFlex) Google Maps Geolocation RequestDemonstrates how make a Google Maps Geolocation REST API request.
Use ChilkatAx-win32.pkg Procedure Test Handle hoRest Boolean iBTls Integer iPort Boolean iBAutoReconnect Boolean iSuccess Handle hoJson Variant vACellTowers Handle hoACellTowers Variant vOCellTower Handle hoOCellTower Variant vAWifi Handle hoAWifi Variant vOPoint Handle hoOPoint String sResponseJson Handle hoJsonResp Variant vJsonLoc Handle hoJsonLoc String sLatitude String sLongitude String sAccuracy String sTemp1 Integer iTemp1 Boolean bTemp1 // 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. Get Create (RefClass(cComChilkatRest)) To hoRest If (Not(IsComObjectCreated(hoRest))) Begin Send CreateComObject of hoRest End // Connect to the Google API REST server. Move True To iBTls Move 443 To iPort Move True To iBAutoReconnect Get ComConnect Of hoRest "www.googleapis.com" iPort iBTls iBAutoReconnect To iSuccess // Add the Content-Type request header. Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess // Add your API key as a query parameter Get ComAddQueryParam Of hoRest "key" "YOUR_API_KEY" To iSuccess // 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 // } // ] // } Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComAppendInt Of hoJson "homeMobileCountryCode" 310 To iSuccess Get ComAppendInt Of hoJson "homeMobileNetworkCode" 260 To iSuccess Get ComAppendString Of hoJson "radioType" "gsm" To iSuccess Get ComAppendString Of hoJson "carrier" "T-Mobile" To iSuccess Get ComAppendArray Of hoJson "cellTowers" To vACellTowers If (IsComObject(vACellTowers)) Begin Get Create (RefClass(cComChilkatJsonArray)) To hoACellTowers Set pvComObject Of hoACellTowers To vACellTowers End Get ComAddObjectAt Of hoACellTowers 0 To iSuccess Get ComObjectAt Of hoACellTowers 0 To vOCellTower If (IsComObject(vOCellTower)) Begin Get Create (RefClass(cComChilkatJsonObject)) To hoOCellTower Set pvComObject Of hoOCellTower To vOCellTower End Get ComAppendInt Of hoOCellTower "cellId" 39627456 To iSuccess Get ComAppendInt Of hoOCellTower "locationAreaCode" 40495 To iSuccess Get ComAppendInt Of hoOCellTower "mobileCountryCode" 310 To iSuccess Get ComAppendInt Of hoOCellTower "mobileNetworkCode" 260 To iSuccess Get ComAppendInt Of hoOCellTower "age" 0 To iSuccess Get ComAppendInt Of hoOCellTower "signalStrength" -95 To iSuccess Send Destroy of hoOCellTower Send Destroy of hoACellTowers Get ComAppendArray Of hoJson "wifiAccessPoints" To vAWifi If (IsComObject(vAWifi)) Begin Get Create (RefClass(cComChilkatJsonArray)) To hoAWifi Set pvComObject Of hoAWifi To vAWifi End Get ComAddObjectAt Of hoAWifi 0 To iSuccess Get ComObjectAt Of hoAWifi 0 To vOPoint If (IsComObject(vOPoint)) Begin Get Create (RefClass(cComChilkatJsonObject)) To hoOPoint Set pvComObject Of hoOPoint To vOPoint End Get ComAppendString Of hoOPoint "macAddress" "01:23:45:67:89:AB" To iSuccess Get ComAppendInt Of hoOPoint "signalStrength" 8 To iSuccess Get ComAppendInt Of hoOPoint "age" 0 To iSuccess Get ComAppendInt Of hoOPoint "signalToNoiseRatio" -65 To iSuccess Get ComAppendInt Of hoOPoint "channel" 8 To iSuccess Send Destroy of hoOPoint Get ComAddObjectAt Of hoAWifi 1 To iSuccess Get ComObjectAt Of hoAWifi 1 To vOPoint If (IsComObject(vOPoint)) Begin Get Create (RefClass(cComChilkatJsonObject)) To hoOPoint Set pvComObject Of hoOPoint To vOPoint End Get ComAppendString Of hoOPoint "macAddress" "01:23:45:67:89:AC" To iSuccess Get ComAppendInt Of hoOPoint "signalStrength" 4 To iSuccess Get ComAppendInt Of hoOPoint "age" 0 To iSuccess Send Destroy of hoOPoint Send Destroy of hoAWifi Get ComEmit Of hoJson To sTemp1 Get ComFullRequestString Of hoRest "POST" "/geolocation/v1/geolocate" sTemp1 To sResponseJson Get ComLastMethodSuccess Of hoRest To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End // When successful, the response code is 200. Get ComResponseStatusCode Of hoRest To iTemp1 If (iTemp1 <> 200) Begin // Examine the request/response to see what happened. Get ComResponseStatusCode Of hoRest To iTemp1 Showln "response status code = " iTemp1 Get ComResponseStatusText Of hoRest To sTemp1 Showln "response status text = " sTemp1 Get ComResponseHeader Of hoRest To sTemp1 Showln "response header: " sTemp1 Showln "response JSON: " sResponseJson Showln "---" Get ComLastRequestStartLine Of hoRest To sTemp1 Showln "LastRequestStartLine: " sTemp1 Get ComLastRequestHeader Of hoRest To sTemp1 Showln "LastRequestHeader: " sTemp1 Procedure_Return End Set ComEmitCompact Of hoJson To False Get ComEmit Of hoJson To sTemp1 Showln "JSON request body: " sTemp1 // The JSON response should look like this: // { // "location": { // "lat": 37.4248297, // "lng": -122.07346549999998 // }, // "accuracy": 1145.0 // } Showln "JSON response: " sResponseJson Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResp If (Not(IsComObjectCreated(hoJsonResp))) Begin Send CreateComObject of hoJsonResp End Get ComLoad Of hoJsonResp sResponseJson To iSuccess Get ComObjectOf Of hoJsonResp "location" To vJsonLoc If (IsComObject(vJsonLoc)) Begin Get Create (RefClass(cComChilkatJsonObject)) To hoJsonLoc Set pvComObject Of hoJsonLoc To vJsonLoc End // Any JSON value can be obtained as a string.. Get ComStringOf Of hoJsonLoc "lat" To sLatitude Showln "latitude = " sLatitude Get ComStringOf Of hoJsonLoc "lng" To sLongitude Showln "longitude = " sLongitude Send Destroy of hoJsonLoc Get ComStringOf Of hoJsonResp "accuracy" To sAccuracy Showln "accuracy = " sAccuracy End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.