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
(Unicode C) Azure Maps Get Search AddressGet information for a given address. For more information, see https://docs.microsoft.com/en-us/rest/api/maps/search/getsearchaddress
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; const wchar_t *url; const wchar_t *strResp; HCkJsonObjectW jsonResponse; const wchar_t *summaryQuery; const wchar_t *summaryQueryType; int summaryQueryTime; int summaryNumResults; int summaryOffset; int summaryTotalResults; int summaryFuzzyLevel; int i; int count_i; const wchar_t *v_type; const wchar_t *id; const wchar_t *score; const wchar_t *addressStreetNumber; const wchar_t *addressStreetName; const wchar_t *addressMunicipalitySubdivision; const wchar_t *addressMunicipality; const wchar_t *addressCountrySecondarySubdivision; const wchar_t *addressCountryTertiarySubdivision; const wchar_t *addressCountrySubdivision; const wchar_t *addressPostalCode; const wchar_t *addressExtendedPostalCode; const wchar_t *addressCountryCode; const wchar_t *addressCountry; const wchar_t *addressCountryCodeISO3; const wchar_t *addressFreeformAddress; const wchar_t *addressCountrySubdivisionName; const wchar_t *positionLat; const wchar_t *positionLon; const wchar_t *viewportTopLeftPointLat; const wchar_t *viewportTopLeftPointLon; const wchar_t *viewportBtmRightPointLat; const wchar_t *viewportBtmRightPointLon; int j; int count_j; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); CkHttpW_putAccept(http,L"application/json"); url = L"https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}"; CkHttpW_SetUrlVar(http,L"format",L"json"); CkHttpW_SetUrlVar(http,L"query",L"15127 NE 24th Street, Redmond, WA 98052"); strResp = CkHttpW_quickGetStr(http,url); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); return; } wprintf(L"Response Status Code: %d\n",CkHttpW_getLastStatus(http)); jsonResponse = CkJsonObjectW_Create(); CkJsonObjectW_Load(jsonResponse,strResp); CkJsonObjectW_putEmitCompact(jsonResponse,FALSE); wprintf(L"%s\n",CkJsonObjectW_emit(jsonResponse)); if (CkHttpW_getLastStatus(http) != 200) { wprintf(L"Failed.\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonResponse); return; } // Sample output... // (See the parsing code below..) // // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "summary": { // "query": "15127 NE 24th Street, Redmond, WA 98052", // "queryType": "NON_NEAR", // "queryTime": 58, // "numResults": 1, // "offset": 0, // "totalResults": 1, // "fuzzyLevel": 1 // }, // "results": [ // { // "type": "Point Address", // "id": "US/PAD/p0/19173426", // "score": 14.51, // "address": { // "streetNumber": "15127", // "streetName": "NE 24th St", // "municipalitySubdivision": "Redmond", // "municipality": "Redmond, Adelaide, Ames Lake, Avondale, Earlmount", // "countrySecondarySubdivision": "King", // "countryTertiarySubdivision": "Seattle East", // "countrySubdivision": "WA", // "postalCode": "98052", // "extendedPostalCode": "980525544", // "countryCode": "US", // "country": "United States Of America", // "countryCodeISO3": "USA", // "freeformAddress": "15127 NE 24th St, Redmond, WA 980525544", // "countrySubdivisionName": "Washington" // }, // "position": { // "lat": 47.6308, // "lon": -122.1385 // }, // "viewport": { // "topLeftPoint": { // "lat": 47.6317, // "lon": -122.13983 // }, // "btmRightPoint": { // "lat": 47.6299, // "lon": -122.13717 // } // }, // "entryPoints": [ // { // "type": "main", // "position": { // "lat": 47.6315, // "lon": -122.13852 // } // } // ] // } // ] // } // summaryQuery = CkJsonObjectW_stringOf(jsonResponse,L"summary.query"); summaryQueryType = CkJsonObjectW_stringOf(jsonResponse,L"summary.queryType"); summaryQueryTime = CkJsonObjectW_IntOf(jsonResponse,L"summary.queryTime"); summaryNumResults = CkJsonObjectW_IntOf(jsonResponse,L"summary.numResults"); summaryOffset = CkJsonObjectW_IntOf(jsonResponse,L"summary.offset"); summaryTotalResults = CkJsonObjectW_IntOf(jsonResponse,L"summary.totalResults"); summaryFuzzyLevel = CkJsonObjectW_IntOf(jsonResponse,L"summary.fuzzyLevel"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"results"); while (i < count_i) { CkJsonObjectW_putI(jsonResponse,i); v_type = CkJsonObjectW_stringOf(jsonResponse,L"results[i].type"); id = CkJsonObjectW_stringOf(jsonResponse,L"results[i].id"); score = CkJsonObjectW_stringOf(jsonResponse,L"results[i].score"); addressStreetNumber = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.streetNumber"); addressStreetName = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.streetName"); addressMunicipalitySubdivision = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.municipalitySubdivision"); addressMunicipality = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.municipality"); addressCountrySecondarySubdivision = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.countrySecondarySubdivision"); addressCountryTertiarySubdivision = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.countryTertiarySubdivision"); addressCountrySubdivision = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.countrySubdivision"); addressPostalCode = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.postalCode"); addressExtendedPostalCode = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.extendedPostalCode"); addressCountryCode = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.countryCode"); addressCountry = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.country"); addressCountryCodeISO3 = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.countryCodeISO3"); addressFreeformAddress = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.freeformAddress"); addressCountrySubdivisionName = CkJsonObjectW_stringOf(jsonResponse,L"results[i].address.countrySubdivisionName"); positionLat = CkJsonObjectW_stringOf(jsonResponse,L"results[i].position.lat"); positionLon = CkJsonObjectW_stringOf(jsonResponse,L"results[i].position.lon"); viewportTopLeftPointLat = CkJsonObjectW_stringOf(jsonResponse,L"results[i].viewport.topLeftPoint.lat"); viewportTopLeftPointLon = CkJsonObjectW_stringOf(jsonResponse,L"results[i].viewport.topLeftPoint.lon"); viewportBtmRightPointLat = CkJsonObjectW_stringOf(jsonResponse,L"results[i].viewport.btmRightPoint.lat"); viewportBtmRightPointLon = CkJsonObjectW_stringOf(jsonResponse,L"results[i].viewport.btmRightPoint.lon"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"results[i].entryPoints"); while (j < count_j) { CkJsonObjectW_putJ(jsonResponse,j); v_type = CkJsonObjectW_stringOf(jsonResponse,L"results[i].entryPoints[j].type"); positionLat = CkJsonObjectW_stringOf(jsonResponse,L"results[i].entryPoints[j].position.lat"); positionLon = CkJsonObjectW_stringOf(jsonResponse,L"results[i].entryPoints[j].position.lon"); j = j + 1; } i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonResponse); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.