Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Azure Maps Get Search AddressGet information for a given address. For more information, see https://docs.microsoft.com/en-us/rest/api/maps/search/getsearchaddress
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject, Http; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; url: PWideChar; strResp: PWideChar; jsonResponse: HCkJsonObject; summaryQuery: PWideChar; summaryQueryType: PWideChar; summaryQueryTime: Integer; summaryNumResults: Integer; summaryOffset: Integer; summaryTotalResults: Integer; summaryFuzzyLevel: Integer; i: Integer; count_i: Integer; v_type: PWideChar; id: PWideChar; score: PWideChar; addressStreetNumber: PWideChar; addressStreetName: PWideChar; addressMunicipalitySubdivision: PWideChar; addressMunicipality: PWideChar; addressCountrySecondarySubdivision: PWideChar; addressCountryTertiarySubdivision: PWideChar; addressCountrySubdivision: PWideChar; addressPostalCode: PWideChar; addressExtendedPostalCode: PWideChar; addressCountryCode: PWideChar; addressCountry: PWideChar; addressCountryCodeISO3: PWideChar; addressFreeformAddress: PWideChar; addressCountrySubdivisionName: PWideChar; positionLat: PWideChar; positionLon: PWideChar; viewportTopLeftPointLat: PWideChar; viewportTopLeftPointLon: PWideChar; viewportBtmRightPointLat: PWideChar; viewportBtmRightPointLon: PWideChar; j: Integer; count_j: Integer; begin // 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) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; Memo1.Lines.Add('Response Status Code: ' + IntToStr(CkHttp_getLastStatus(http))); jsonResponse := CkJsonObject_Create(); CkJsonObject_Load(jsonResponse,strResp); CkJsonObject_putEmitCompact(jsonResponse,False); Memo1.Lines.Add(CkJsonObject__emit(jsonResponse)); if (CkHttp_getLastStatus(http) <> 200) then begin Memo1.Lines.Add('Failed.'); Exit; end; // 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 do begin 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 do begin 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; end; i := i + 1; end; CkHttp_Dispose(http); CkJsonObject_Dispose(jsonResponse); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.