Zig
Zig
Azure Maps Get Search Address
See more Azure Maps Examples
Get information for a given address.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
http.setAccept("application/json");
const url = "https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}";
http.setUrlVar("format", "json") catch {};
http.setUrlVar("query", "15127 NE 24th Street, Redmond, WA 98052") catch {};
const str_resp = http.quickGetStr(alloc, url) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response Status Code: {d}\n", .{http.getLastStatus()});
const json_response = try chilkat.JsonObject.init();
defer json_response.deinit();
json_response.load(str_resp) catch {};
json_response.setEmitCompact(false);
std.debug.print("{s}\n", .{try json_response.emit(alloc)});
if (http.getLastStatus() != 200) {
std.debug.print("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
// }
// }
// ]
// }
// ]
// }
//
var i: i32 = 0;
var v_type: [:0]const u8 = "";
var id: [:0]const u8 = "";
var score: [:0]const u8 = "";
var address_street_number: [:0]const u8 = "";
var address_street_name: [:0]const u8 = "";
var address_municipality_subdivision: [:0]const u8 = "";
var address_municipality: [:0]const u8 = "";
var address_country_secondary_subdivision: [:0]const u8 = "";
var address_country_tertiary_subdivision: [:0]const u8 = "";
var address_country_subdivision: [:0]const u8 = "";
var address_postal_code: [:0]const u8 = "";
var address_extended_postal_code: [:0]const u8 = "";
var address_country_code: [:0]const u8 = "";
var address_country: [:0]const u8 = "";
var address_country_code_iso3: [:0]const u8 = "";
var address_freeform_address: [:0]const u8 = "";
var address_country_subdivision_name: [:0]const u8 = "";
var position_lat: [:0]const u8 = "";
var position_lon: [:0]const u8 = "";
var viewport_top_left_point_lat: [:0]const u8 = "";
var viewport_top_left_point_lon: [:0]const u8 = "";
var viewport_btm_right_point_lat: [:0]const u8 = "";
var viewport_btm_right_point_lon: [:0]const u8 = "";
var j: i32 = 0;
var count_j: i32 = 0;
_ = try json_response.stringOf(alloc, "summary.query");
_ = try json_response.stringOf(alloc, "summary.queryType");
_ = json_response.intOf("summary.queryTime");
_ = json_response.intOf("summary.numResults");
_ = json_response.intOf("summary.offset");
_ = json_response.intOf("summary.totalResults");
_ = json_response.intOf("summary.fuzzyLevel");
i = 0;
const count_i = json_response.sizeOfArray("results");
while (i < count_i) {
json_response.setI(i);
v_type = try json_response.stringOf(alloc, "results[i].type");
id = try json_response.stringOf(alloc, "results[i].id");
score = try json_response.stringOf(alloc, "results[i].score");
address_street_number = try json_response.stringOf(alloc, "results[i].address.streetNumber");
address_street_name = try json_response.stringOf(alloc, "results[i].address.streetName");
address_municipality_subdivision = try json_response.stringOf(alloc, "results[i].address.municipalitySubdivision");
address_municipality = try json_response.stringOf(alloc, "results[i].address.municipality");
address_country_secondary_subdivision = try json_response.stringOf(alloc, "results[i].address.countrySecondarySubdivision");
address_country_tertiary_subdivision = try json_response.stringOf(alloc, "results[i].address.countryTertiarySubdivision");
address_country_subdivision = try json_response.stringOf(alloc, "results[i].address.countrySubdivision");
address_postal_code = try json_response.stringOf(alloc, "results[i].address.postalCode");
address_extended_postal_code = try json_response.stringOf(alloc, "results[i].address.extendedPostalCode");
address_country_code = try json_response.stringOf(alloc, "results[i].address.countryCode");
address_country = try json_response.stringOf(alloc, "results[i].address.country");
address_country_code_iso3 = try json_response.stringOf(alloc, "results[i].address.countryCodeISO3");
address_freeform_address = try json_response.stringOf(alloc, "results[i].address.freeformAddress");
address_country_subdivision_name = try json_response.stringOf(alloc, "results[i].address.countrySubdivisionName");
position_lat = try json_response.stringOf(alloc, "results[i].position.lat");
position_lon = try json_response.stringOf(alloc, "results[i].position.lon");
viewport_top_left_point_lat = try json_response.stringOf(alloc, "results[i].viewport.topLeftPoint.lat");
viewport_top_left_point_lon = try json_response.stringOf(alloc, "results[i].viewport.topLeftPoint.lon");
viewport_btm_right_point_lat = try json_response.stringOf(alloc, "results[i].viewport.btmRightPoint.lat");
viewport_btm_right_point_lon = try json_response.stringOf(alloc, "results[i].viewport.btmRightPoint.lon");
j = 0;
count_j = json_response.sizeOfArray("results[i].entryPoints");
while (j < count_j) {
json_response.setJ(j);
v_type = try json_response.stringOf(alloc, "results[i].entryPoints[j].type");
position_lat = try json_response.stringOf(alloc, "results[i].entryPoints[j].position.lat");
position_lon = try json_response.stringOf(alloc, "results[i].entryPoints[j].position.lon");
j = j + 1;
}
i = i + 1;
}
}