PowerBuilder
PowerBuilder
Azure Maps Get Search Address
See more Azure Maps Examples
Get information for a given address.Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Http
string ls_Url
string ls_StrResp
oleobject loo_JsonResponse
string ls_SummaryQuery
string ls_SummaryQueryType
integer li_SummaryQueryTime
integer li_SummaryNumResults
integer li_SummaryOffset
integer li_SummaryTotalResults
integer li_SummaryFuzzyLevel
integer i
integer li_Count_i
string ls_V_type
string ls_Id
string ls_Score
string ls_AddressStreetNumber
string ls_AddressStreetName
string ls_AddressMunicipalitySubdivision
string ls_AddressMunicipality
string ls_AddressCountrySecondarySubdivision
string ls_AddressCountryTertiarySubdivision
string ls_AddressCountrySubdivision
string ls_AddressPostalCode
string ls_AddressExtendedPostalCode
string ls_AddressCountryCode
string ls_AddressCountry
string ls_AddressCountryCodeISO3
string ls_AddressFreeformAddress
string ls_AddressCountrySubdivisionName
string ls_PositionLat
string ls_PositionLon
string ls_ViewportTopLeftPointLat
string ls_ViewportTopLeftPointLon
string ls_ViewportBtmRightPointLat
string ls_ViewportBtmRightPointLon
integer j
integer li_Count_j
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.Accept = "application/json"
ls_Url = "https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}"
loo_Http.SetUrlVar("format","json")
loo_Http.SetUrlVar("query","15127 NE 24th Street, Redmond, WA 98052")
ls_StrResp = loo_Http.QuickGetStr(ls_Url)
if loo_Http.LastMethodSuccess <> 1 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
return
end if
Write-Debug "Response Status Code: " + string(loo_Http.LastStatus)
loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonResponse.Load(ls_StrResp)
loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()
if loo_Http.LastStatus <> 200 then
Write-Debug "Failed."
destroy loo_Http
destroy loo_JsonResponse
return
end if
// 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
// }
// }
// ]
// }
// ]
// }
//
ls_SummaryQuery = loo_JsonResponse.StringOf("summary.query")
ls_SummaryQueryType = loo_JsonResponse.StringOf("summary.queryType")
li_SummaryQueryTime = loo_JsonResponse.IntOf("summary.queryTime")
li_SummaryNumResults = loo_JsonResponse.IntOf("summary.numResults")
li_SummaryOffset = loo_JsonResponse.IntOf("summary.offset")
li_SummaryTotalResults = loo_JsonResponse.IntOf("summary.totalResults")
li_SummaryFuzzyLevel = loo_JsonResponse.IntOf("summary.fuzzyLevel")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("results")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_V_type = loo_JsonResponse.StringOf("results[i].type")
ls_Id = loo_JsonResponse.StringOf("results[i].id")
ls_Score = loo_JsonResponse.StringOf("results[i].score")
ls_AddressStreetNumber = loo_JsonResponse.StringOf("results[i].address.streetNumber")
ls_AddressStreetName = loo_JsonResponse.StringOf("results[i].address.streetName")
ls_AddressMunicipalitySubdivision = loo_JsonResponse.StringOf("results[i].address.municipalitySubdivision")
ls_AddressMunicipality = loo_JsonResponse.StringOf("results[i].address.municipality")
ls_AddressCountrySecondarySubdivision = loo_JsonResponse.StringOf("results[i].address.countrySecondarySubdivision")
ls_AddressCountryTertiarySubdivision = loo_JsonResponse.StringOf("results[i].address.countryTertiarySubdivision")
ls_AddressCountrySubdivision = loo_JsonResponse.StringOf("results[i].address.countrySubdivision")
ls_AddressPostalCode = loo_JsonResponse.StringOf("results[i].address.postalCode")
ls_AddressExtendedPostalCode = loo_JsonResponse.StringOf("results[i].address.extendedPostalCode")
ls_AddressCountryCode = loo_JsonResponse.StringOf("results[i].address.countryCode")
ls_AddressCountry = loo_JsonResponse.StringOf("results[i].address.country")
ls_AddressCountryCodeISO3 = loo_JsonResponse.StringOf("results[i].address.countryCodeISO3")
ls_AddressFreeformAddress = loo_JsonResponse.StringOf("results[i].address.freeformAddress")
ls_AddressCountrySubdivisionName = loo_JsonResponse.StringOf("results[i].address.countrySubdivisionName")
ls_PositionLat = loo_JsonResponse.StringOf("results[i].position.lat")
ls_PositionLon = loo_JsonResponse.StringOf("results[i].position.lon")
ls_ViewportTopLeftPointLat = loo_JsonResponse.StringOf("results[i].viewport.topLeftPoint.lat")
ls_ViewportTopLeftPointLon = loo_JsonResponse.StringOf("results[i].viewport.topLeftPoint.lon")
ls_ViewportBtmRightPointLat = loo_JsonResponse.StringOf("results[i].viewport.btmRightPoint.lat")
ls_ViewportBtmRightPointLon = loo_JsonResponse.StringOf("results[i].viewport.btmRightPoint.lon")
j = 0
li_Count_j = loo_JsonResponse.SizeOfArray("results[i].entryPoints")
do while j < li_Count_j
loo_JsonResponse.J = j
ls_V_type = loo_JsonResponse.StringOf("results[i].entryPoints[j].type")
ls_PositionLat = loo_JsonResponse.StringOf("results[i].entryPoints[j].position.lat")
ls_PositionLon = loo_JsonResponse.StringOf("results[i].entryPoints[j].position.lon")
j = j + 1
loop
i = i + 1
loop
destroy loo_Http
destroy loo_JsonResponse