Unicode C++
Unicode C++
Azure Maps Get Search Address
See more Azure Maps Examples
Get information for a given address.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
http.put_Accept(L"application/json");
const wchar_t *url = L"https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}";
http.SetUrlVar(L"format",L"json");
http.SetUrlVar(L"query",L"15127 NE 24th Street, Redmond, WA 98052");
const wchar_t *strResp = http.quickGetStr(url);
if (http.get_LastMethodSuccess() != true) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
wprintf(L"Response Status Code: %d\n",http.get_LastStatus());
CkJsonObjectW jsonResponse;
jsonResponse.Load(strResp);
jsonResponse.put_EmitCompact(false);
wprintf(L"%s\n",jsonResponse.emit());
if (http.get_LastStatus() != 200) {
wprintf(L"Failed.\n");
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
// }
// }
// ]
// }
// ]
// }
//
const wchar_t *summaryQuery = 0;
const wchar_t *summaryQueryType = 0;
int summaryQueryTime;
int summaryNumResults;
int summaryOffset;
int summaryTotalResults;
int summaryFuzzyLevel;
int i;
int count_i;
const wchar_t *v_type = 0;
const wchar_t *id = 0;
const wchar_t *score = 0;
const wchar_t *addressStreetNumber = 0;
const wchar_t *addressStreetName = 0;
const wchar_t *addressMunicipalitySubdivision = 0;
const wchar_t *addressMunicipality = 0;
const wchar_t *addressCountrySecondarySubdivision = 0;
const wchar_t *addressCountryTertiarySubdivision = 0;
const wchar_t *addressCountrySubdivision = 0;
const wchar_t *addressPostalCode = 0;
const wchar_t *addressExtendedPostalCode = 0;
const wchar_t *addressCountryCode = 0;
const wchar_t *addressCountry = 0;
const wchar_t *addressCountryCodeISO3 = 0;
const wchar_t *addressFreeformAddress = 0;
const wchar_t *addressCountrySubdivisionName = 0;
const wchar_t *positionLat = 0;
const wchar_t *positionLon = 0;
const wchar_t *viewportTopLeftPointLat = 0;
const wchar_t *viewportTopLeftPointLon = 0;
const wchar_t *viewportBtmRightPointLat = 0;
const wchar_t *viewportBtmRightPointLon = 0;
int j;
int count_j;
summaryQuery = jsonResponse.stringOf(L"summary.query");
summaryQueryType = jsonResponse.stringOf(L"summary.queryType");
summaryQueryTime = jsonResponse.IntOf(L"summary.queryTime");
summaryNumResults = jsonResponse.IntOf(L"summary.numResults");
summaryOffset = jsonResponse.IntOf(L"summary.offset");
summaryTotalResults = jsonResponse.IntOf(L"summary.totalResults");
summaryFuzzyLevel = jsonResponse.IntOf(L"summary.fuzzyLevel");
i = 0;
count_i = jsonResponse.SizeOfArray(L"results");
while (i < count_i) {
jsonResponse.put_I(i);
v_type = jsonResponse.stringOf(L"results[i].type");
id = jsonResponse.stringOf(L"results[i].id");
score = jsonResponse.stringOf(L"results[i].score");
addressStreetNumber = jsonResponse.stringOf(L"results[i].address.streetNumber");
addressStreetName = jsonResponse.stringOf(L"results[i].address.streetName");
addressMunicipalitySubdivision = jsonResponse.stringOf(L"results[i].address.municipalitySubdivision");
addressMunicipality = jsonResponse.stringOf(L"results[i].address.municipality");
addressCountrySecondarySubdivision = jsonResponse.stringOf(L"results[i].address.countrySecondarySubdivision");
addressCountryTertiarySubdivision = jsonResponse.stringOf(L"results[i].address.countryTertiarySubdivision");
addressCountrySubdivision = jsonResponse.stringOf(L"results[i].address.countrySubdivision");
addressPostalCode = jsonResponse.stringOf(L"results[i].address.postalCode");
addressExtendedPostalCode = jsonResponse.stringOf(L"results[i].address.extendedPostalCode");
addressCountryCode = jsonResponse.stringOf(L"results[i].address.countryCode");
addressCountry = jsonResponse.stringOf(L"results[i].address.country");
addressCountryCodeISO3 = jsonResponse.stringOf(L"results[i].address.countryCodeISO3");
addressFreeformAddress = jsonResponse.stringOf(L"results[i].address.freeformAddress");
addressCountrySubdivisionName = jsonResponse.stringOf(L"results[i].address.countrySubdivisionName");
positionLat = jsonResponse.stringOf(L"results[i].position.lat");
positionLon = jsonResponse.stringOf(L"results[i].position.lon");
viewportTopLeftPointLat = jsonResponse.stringOf(L"results[i].viewport.topLeftPoint.lat");
viewportTopLeftPointLon = jsonResponse.stringOf(L"results[i].viewport.topLeftPoint.lon");
viewportBtmRightPointLat = jsonResponse.stringOf(L"results[i].viewport.btmRightPoint.lat");
viewportBtmRightPointLon = jsonResponse.stringOf(L"results[i].viewport.btmRightPoint.lon");
j = 0;
count_j = jsonResponse.SizeOfArray(L"results[i].entryPoints");
while (j < count_j) {
jsonResponse.put_J(j);
v_type = jsonResponse.stringOf(L"results[i].entryPoints[j].type");
positionLat = jsonResponse.stringOf(L"results[i].entryPoints[j].position.lat");
positionLon = jsonResponse.stringOf(L"results[i].entryPoints[j].position.lon");
j = j + 1;
}
i = i + 1;
}
}