Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Google Maps Geolocation Request

Demonstrates how make a Google Maps Geolocation REST API request.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

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.