Sample code for 30+ languages & platforms
Rust

Azure Maps Get Search Address

See more Azure Maps Examples

Get information for a given address.

Chilkat Rust Downloads

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

let http = chilkat::Http::new();

http.set_accept("application/json");

let url = "https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}".to_string();

let _ = http.set_url_var("format", "json");
let _ = http.set_url_var("query", "15127 NE 24th Street, Redmond, WA 98052");

let Ok(str_resp) = http.quick_get_str(&url) else {
    println!("{}", http.last_error_text());
    return;
};

println!("Response Status Code: {}", http.last_status());

let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&str_resp);
json_response.set_emit_compact(false);
println!("{}", json_response.emit().unwrap_or_default());

if http.last_status() != 200 {
    println!("Failed.");
    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
//           }
//         }
//       ]
//     }
//   ]
// }
// 

let mut i: i32 = 0;
let mut j: i32 = 0;
let mut count_j: i32 = 0;

let summary_query = json_response.string_of("summary.query").unwrap_or_default();
let summary_query_type = json_response.string_of("summary.queryType").unwrap_or_default();
let summary_query_time = json_response.int_of("summary.queryTime");
let summary_num_results = json_response.int_of("summary.numResults");
let summary_offset = json_response.int_of("summary.offset");
let summary_total_results = json_response.int_of("summary.totalResults");
let summary_fuzzy_level = json_response.int_of("summary.fuzzyLevel");
i = 0;
let count_i = json_response.size_of_array("results");
while i < count_i {
    json_response.set_i(i);
    let _ = json_response.string_of("results[i].type").unwrap_or_default();
    let _ = json_response.string_of("results[i].id").unwrap_or_default();
    let _ = json_response.string_of("results[i].score").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.streetNumber").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.streetName").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.municipalitySubdivision").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.municipality").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.countrySecondarySubdivision").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.countryTertiarySubdivision").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.countrySubdivision").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.postalCode").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.extendedPostalCode").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.countryCode").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.country").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.countryCodeISO3").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.freeformAddress").unwrap_or_default();
    let _ = json_response.string_of("results[i].address.countrySubdivisionName").unwrap_or_default();
    let _ = json_response.string_of("results[i].position.lat").unwrap_or_default();
    let _ = json_response.string_of("results[i].position.lon").unwrap_or_default();
    let _ = json_response.string_of("results[i].viewport.topLeftPoint.lat").unwrap_or_default();
    let _ = json_response.string_of("results[i].viewport.topLeftPoint.lon").unwrap_or_default();
    let _ = json_response.string_of("results[i].viewport.btmRightPoint.lat").unwrap_or_default();
    let _ = json_response.string_of("results[i].viewport.btmRightPoint.lon").unwrap_or_default();
    j = 0;
    count_j = json_response.size_of_array("results[i].entryPoints");
    while j < count_j {
        json_response.set_j(j);
        let _ = json_response.string_of("results[i].entryPoints[j].type").unwrap_or_default();
        let _ = json_response.string_of("results[i].entryPoints[j].position.lat").unwrap_or_default();
        let _ = json_response.string_of("results[i].entryPoints[j].position.lon").unwrap_or_default();
        j = j + 1;
    }

    i = i + 1;
}