Sample code for 30+ languages & platforms
Xbase++

Azure Maps Get Search Address

See more Azure Maps Examples

Get information for a given address.

Chilkat Xbase++ Downloads

Xbase++
LOCAL oHttp
LOCAL cUrl
LOCAL cStrResp
LOCAL oJsonResponse
LOCAL cSummaryQuery
LOCAL cSummaryQueryType
LOCAL nSummaryQueryTime
LOCAL nSummaryNumResults
LOCAL nSummaryOffset
LOCAL nSummaryTotalResults
LOCAL nSummaryFuzzyLevel
LOCAL i
LOCAL nCount_i
LOCAL cV_type
LOCAL cId
LOCAL cScore
LOCAL cAddressStreetNumber
LOCAL cAddressStreetName
LOCAL cAddressMunicipalitySubdivision
LOCAL cAddressMunicipality
LOCAL cAddressCountrySecondarySubdivision
LOCAL cAddressCountryTertiarySubdivision
LOCAL cAddressCountrySubdivision
LOCAL cAddressPostalCode
LOCAL cAddressExtendedPostalCode
LOCAL cAddressCountryCode
LOCAL cAddressCountry
LOCAL cAddressCountryCodeISO3
LOCAL cAddressFreeformAddress
LOCAL cAddressCountrySubdivisionName
LOCAL cPositionLat
LOCAL cPositionLon
LOCAL cViewportTopLeftPointLat
LOCAL cViewportTopLeftPointLon
LOCAL cViewportBtmRightPointLat
LOCAL cViewportBtmRightPointLon
LOCAL j
LOCAL nCount_j

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

oHttp:Accept := "application/json"

cUrl := "https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}"

oHttp:SetUrlVar("format", "json")
oHttp:SetUrlVar("query", "15127 NE 24th Street, Redmond, WA 98052")

cStrResp := oHttp:QuickGetStr(cUrl)
IF (oHttp:LastMethodSuccess != 1)
    ? oHttp:LastErrorText
    oHttp:destroy()
    RETURN
ENDIF

? "Response Status Code: " + Str(oHttp:LastStatus)

oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(cStrResp)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()

IF (oHttp:LastStatus != 200)
    ? "Failed."
    oHttp:destroy()
    oJsonResponse:destroy()
    RETURN
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
//            }
//          }
//        ]
//      }
//    ]
//  }
//  

cSummaryQuery := oJsonResponse:StringOf("summary.query")
cSummaryQueryType := oJsonResponse:StringOf("summary.queryType")
nSummaryQueryTime := oJsonResponse:IntOf("summary.queryTime")
nSummaryNumResults := oJsonResponse:IntOf("summary.numResults")
nSummaryOffset := oJsonResponse:IntOf("summary.offset")
nSummaryTotalResults := oJsonResponse:IntOf("summary.totalResults")
nSummaryFuzzyLevel := oJsonResponse:IntOf("summary.fuzzyLevel")
i := 0
nCount_i := oJsonResponse:SizeOfArray("results")
DO WHILE i < nCount_i
    oJsonResponse:I := i
    cV_type := oJsonResponse:StringOf("results[i].type")
    cId := oJsonResponse:StringOf("results[i].id")
    cScore := oJsonResponse:StringOf("results[i].score")
    cAddressStreetNumber := oJsonResponse:StringOf("results[i].address.streetNumber")
    cAddressStreetName := oJsonResponse:StringOf("results[i].address.streetName")
    cAddressMunicipalitySubdivision := oJsonResponse:StringOf("results[i].address.municipalitySubdivision")
    cAddressMunicipality := oJsonResponse:StringOf("results[i].address.municipality")
    cAddressCountrySecondarySubdivision := oJsonResponse:StringOf("results[i].address.countrySecondarySubdivision")
    cAddressCountryTertiarySubdivision := oJsonResponse:StringOf("results[i].address.countryTertiarySubdivision")
    cAddressCountrySubdivision := oJsonResponse:StringOf("results[i].address.countrySubdivision")
    cAddressPostalCode := oJsonResponse:StringOf("results[i].address.postalCode")
    cAddressExtendedPostalCode := oJsonResponse:StringOf("results[i].address.extendedPostalCode")
    cAddressCountryCode := oJsonResponse:StringOf("results[i].address.countryCode")
    cAddressCountry := oJsonResponse:StringOf("results[i].address.country")
    cAddressCountryCodeISO3 := oJsonResponse:StringOf("results[i].address.countryCodeISO3")
    cAddressFreeformAddress := oJsonResponse:StringOf("results[i].address.freeformAddress")
    cAddressCountrySubdivisionName := oJsonResponse:StringOf("results[i].address.countrySubdivisionName")
    cPositionLat := oJsonResponse:StringOf("results[i].position.lat")
    cPositionLon := oJsonResponse:StringOf("results[i].position.lon")
    cViewportTopLeftPointLat := oJsonResponse:StringOf("results[i].viewport.topLeftPoint.lat")
    cViewportTopLeftPointLon := oJsonResponse:StringOf("results[i].viewport.topLeftPoint.lon")
    cViewportBtmRightPointLat := oJsonResponse:StringOf("results[i].viewport.btmRightPoint.lat")
    cViewportBtmRightPointLon := oJsonResponse:StringOf("results[i].viewport.btmRightPoint.lon")
    j := 0
    nCount_j := oJsonResponse:SizeOfArray("results[i].entryPoints")
    DO WHILE j < nCount_j
        oJsonResponse:J := j
        cV_type := oJsonResponse:StringOf("results[i].entryPoints[j].type")
        cPositionLat := oJsonResponse:StringOf("results[i].entryPoints[j].position.lat")
        cPositionLon := oJsonResponse:StringOf("results[i].entryPoints[j].position.lon")
        j := j + 1
    ENDDO
    i := i + 1
ENDDO

oHttp:destroy()
oJsonResponse:destroy()