PureBasic
PureBasic
Azure Maps Get Search Address
See more Azure Maps Examples
Get information for a given address.Chilkat PureBasic Downloads
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttp::setCkAccept(http, "application/json")
url.s = "https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}"
CkHttp::ckSetUrlVar(http,"format","json")
CkHttp::ckSetUrlVar(http,"query","15127 NE 24th Street, Redmond, WA 98052")
strResp.s = CkHttp::ckQuickGetStr(http,url)
If CkHttp::ckLastMethodSuccess(http) <> 1
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
ProcedureReturn
EndIf
Debug "Response Status Code: " + Str(CkHttp::ckLastStatus(http))
jsonResponse.i = CkJsonObject::ckCreate()
If jsonResponse.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(jsonResponse,strResp)
CkJsonObject::setCkEmitCompact(jsonResponse, 0)
Debug CkJsonObject::ckEmit(jsonResponse)
If CkHttp::ckLastStatus(http) <> 200
Debug "Failed."
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonResponse)
ProcedureReturn
EndIf
; 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.s
summaryQueryType.s
summaryQueryTime.i
summaryNumResults.i
summaryOffset.i
summaryTotalResults.i
summaryFuzzyLevel.i
i.i
count_i.i
v_type.s
id.s
score.s
addressStreetNumber.s
addressStreetName.s
addressMunicipalitySubdivision.s
addressMunicipality.s
addressCountrySecondarySubdivision.s
addressCountryTertiarySubdivision.s
addressCountrySubdivision.s
addressPostalCode.s
addressExtendedPostalCode.s
addressCountryCode.s
addressCountry.s
addressCountryCodeISO3.s
addressFreeformAddress.s
addressCountrySubdivisionName.s
positionLat.s
positionLon.s
viewportTopLeftPointLat.s
viewportTopLeftPointLon.s
viewportBtmRightPointLat.s
viewportBtmRightPointLon.s
j.i
count_j.i
summaryQuery = CkJsonObject::ckStringOf(jsonResponse,"summary.query")
summaryQueryType = CkJsonObject::ckStringOf(jsonResponse,"summary.queryType")
summaryQueryTime = CkJsonObject::ckIntOf(jsonResponse,"summary.queryTime")
summaryNumResults = CkJsonObject::ckIntOf(jsonResponse,"summary.numResults")
summaryOffset = CkJsonObject::ckIntOf(jsonResponse,"summary.offset")
summaryTotalResults = CkJsonObject::ckIntOf(jsonResponse,"summary.totalResults")
summaryFuzzyLevel = CkJsonObject::ckIntOf(jsonResponse,"summary.fuzzyLevel")
i = 0
count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"results")
While i < count_i
CkJsonObject::setCkI(jsonResponse, i)
v_type = CkJsonObject::ckStringOf(jsonResponse,"results[i].type")
id = CkJsonObject::ckStringOf(jsonResponse,"results[i].id")
score = CkJsonObject::ckStringOf(jsonResponse,"results[i].score")
addressStreetNumber = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.streetNumber")
addressStreetName = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.streetName")
addressMunicipalitySubdivision = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.municipalitySubdivision")
addressMunicipality = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.municipality")
addressCountrySecondarySubdivision = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.countrySecondarySubdivision")
addressCountryTertiarySubdivision = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.countryTertiarySubdivision")
addressCountrySubdivision = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.countrySubdivision")
addressPostalCode = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.postalCode")
addressExtendedPostalCode = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.extendedPostalCode")
addressCountryCode = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.countryCode")
addressCountry = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.country")
addressCountryCodeISO3 = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.countryCodeISO3")
addressFreeformAddress = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.freeformAddress")
addressCountrySubdivisionName = CkJsonObject::ckStringOf(jsonResponse,"results[i].address.countrySubdivisionName")
positionLat = CkJsonObject::ckStringOf(jsonResponse,"results[i].position.lat")
positionLon = CkJsonObject::ckStringOf(jsonResponse,"results[i].position.lon")
viewportTopLeftPointLat = CkJsonObject::ckStringOf(jsonResponse,"results[i].viewport.topLeftPoint.lat")
viewportTopLeftPointLon = CkJsonObject::ckStringOf(jsonResponse,"results[i].viewport.topLeftPoint.lon")
viewportBtmRightPointLat = CkJsonObject::ckStringOf(jsonResponse,"results[i].viewport.btmRightPoint.lat")
viewportBtmRightPointLon = CkJsonObject::ckStringOf(jsonResponse,"results[i].viewport.btmRightPoint.lon")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"results[i].entryPoints")
While j < count_j
CkJsonObject::setCkJ(jsonResponse, j)
v_type = CkJsonObject::ckStringOf(jsonResponse,"results[i].entryPoints[j].type")
positionLat = CkJsonObject::ckStringOf(jsonResponse,"results[i].entryPoints[j].position.lat")
positionLon = CkJsonObject::ckStringOf(jsonResponse,"results[i].entryPoints[j].position.lon")
j = j + 1
Wend
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonResponse)
ProcedureReturn
EndProcedure