C
C
Azure Maps Get Search Address
See more Azure Maps Examples
Get information for a given address.Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkHttp http;
const char *url;
const char *strResp;
HCkJsonObject jsonResponse;
const char *summaryQuery;
const char *summaryQueryType;
int summaryQueryTime;
int summaryNumResults;
int summaryOffset;
int summaryTotalResults;
int summaryFuzzyLevel;
int i;
int count_i;
const char *v_type;
const char *id;
const char *score;
const char *addressStreetNumber;
const char *addressStreetName;
const char *addressMunicipalitySubdivision;
const char *addressMunicipality;
const char *addressCountrySecondarySubdivision;
const char *addressCountryTertiarySubdivision;
const char *addressCountrySubdivision;
const char *addressPostalCode;
const char *addressExtendedPostalCode;
const char *addressCountryCode;
const char *addressCountry;
const char *addressCountryCodeISO3;
const char *addressFreeformAddress;
const char *addressCountrySubdivisionName;
const char *positionLat;
const char *positionLon;
const char *viewportTopLeftPointLat;
const char *viewportTopLeftPointLon;
const char *viewportBtmRightPointLat;
const char *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 = CkHttp_Create();
CkHttp_putAccept(http,"application/json");
url = "https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}";
CkHttp_SetUrlVar(http,"format","json");
CkHttp_SetUrlVar(http,"query","15127 NE 24th Street, Redmond, WA 98052");
strResp = CkHttp_quickGetStr(http,url);
if (CkHttp_getLastMethodSuccess(http) != TRUE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
return;
}
printf("Response Status Code: %d\n",CkHttp_getLastStatus(http));
jsonResponse = CkJsonObject_Create();
CkJsonObject_Load(jsonResponse,strResp);
CkJsonObject_putEmitCompact(jsonResponse,FALSE);
printf("%s\n",CkJsonObject_emit(jsonResponse));
if (CkHttp_getLastStatus(http) != 200) {
printf("Failed.\n");
CkHttp_Dispose(http);
CkJsonObject_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 = CkJsonObject_stringOf(jsonResponse,"summary.query");
summaryQueryType = CkJsonObject_stringOf(jsonResponse,"summary.queryType");
summaryQueryTime = CkJsonObject_IntOf(jsonResponse,"summary.queryTime");
summaryNumResults = CkJsonObject_IntOf(jsonResponse,"summary.numResults");
summaryOffset = CkJsonObject_IntOf(jsonResponse,"summary.offset");
summaryTotalResults = CkJsonObject_IntOf(jsonResponse,"summary.totalResults");
summaryFuzzyLevel = CkJsonObject_IntOf(jsonResponse,"summary.fuzzyLevel");
i = 0;
count_i = CkJsonObject_SizeOfArray(jsonResponse,"results");
while (i < count_i) {
CkJsonObject_putI(jsonResponse,i);
v_type = CkJsonObject_stringOf(jsonResponse,"results[i].type");
id = CkJsonObject_stringOf(jsonResponse,"results[i].id");
score = CkJsonObject_stringOf(jsonResponse,"results[i].score");
addressStreetNumber = CkJsonObject_stringOf(jsonResponse,"results[i].address.streetNumber");
addressStreetName = CkJsonObject_stringOf(jsonResponse,"results[i].address.streetName");
addressMunicipalitySubdivision = CkJsonObject_stringOf(jsonResponse,"results[i].address.municipalitySubdivision");
addressMunicipality = CkJsonObject_stringOf(jsonResponse,"results[i].address.municipality");
addressCountrySecondarySubdivision = CkJsonObject_stringOf(jsonResponse,"results[i].address.countrySecondarySubdivision");
addressCountryTertiarySubdivision = CkJsonObject_stringOf(jsonResponse,"results[i].address.countryTertiarySubdivision");
addressCountrySubdivision = CkJsonObject_stringOf(jsonResponse,"results[i].address.countrySubdivision");
addressPostalCode = CkJsonObject_stringOf(jsonResponse,"results[i].address.postalCode");
addressExtendedPostalCode = CkJsonObject_stringOf(jsonResponse,"results[i].address.extendedPostalCode");
addressCountryCode = CkJsonObject_stringOf(jsonResponse,"results[i].address.countryCode");
addressCountry = CkJsonObject_stringOf(jsonResponse,"results[i].address.country");
addressCountryCodeISO3 = CkJsonObject_stringOf(jsonResponse,"results[i].address.countryCodeISO3");
addressFreeformAddress = CkJsonObject_stringOf(jsonResponse,"results[i].address.freeformAddress");
addressCountrySubdivisionName = CkJsonObject_stringOf(jsonResponse,"results[i].address.countrySubdivisionName");
positionLat = CkJsonObject_stringOf(jsonResponse,"results[i].position.lat");
positionLon = CkJsonObject_stringOf(jsonResponse,"results[i].position.lon");
viewportTopLeftPointLat = CkJsonObject_stringOf(jsonResponse,"results[i].viewport.topLeftPoint.lat");
viewportTopLeftPointLon = CkJsonObject_stringOf(jsonResponse,"results[i].viewport.topLeftPoint.lon");
viewportBtmRightPointLat = CkJsonObject_stringOf(jsonResponse,"results[i].viewport.btmRightPoint.lat");
viewportBtmRightPointLon = CkJsonObject_stringOf(jsonResponse,"results[i].viewport.btmRightPoint.lon");
j = 0;
count_j = CkJsonObject_SizeOfArray(jsonResponse,"results[i].entryPoints");
while (j < count_j) {
CkJsonObject_putJ(jsonResponse,j);
v_type = CkJsonObject_stringOf(jsonResponse,"results[i].entryPoints[j].type");
positionLat = CkJsonObject_stringOf(jsonResponse,"results[i].entryPoints[j].position.lat");
positionLon = CkJsonObject_stringOf(jsonResponse,"results[i].entryPoints[j].position.lon");
j = j + 1;
}
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonResponse);
}