React Native
React Native
Azure Maps Get Search Address
See more Azure Maps Examples
Get information for a given address.Chilkat React Native Downloads
import { Http, JsonObject } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
http.accept = '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');
http.setUrlVar('query', '15127 NE 24th Street, Redmond, WA 98052');
let strResp: string;
try {
strResp = await http.quickGetStrAsync(url);
} catch {
console.log(http.lastErrorText);
return;
}
console.log(`Response Status Code: ${http.lastStatus}`);
const jsonResponse = new JsonObject();
jsonResponse.load(strResp);
jsonResponse.emitCompact = false;
console.log(jsonResponse.emit());
if (http.lastStatus !== 200) {
console.log('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 i = 0;
let vType = '';
let id = '';
let score = '';
let addressStreetNumber = '';
let addressStreetName = '';
let addressMunicipalitySubdivision = '';
let addressMunicipality = '';
let addressCountrySecondarySubdivision = '';
let addressCountryTertiarySubdivision = '';
let addressCountrySubdivision = '';
let addressPostalCode = '';
let addressExtendedPostalCode = '';
let addressCountryCode = '';
let addressCountry = '';
let addressCountryCodeISO3 = '';
let addressFreeformAddress = '';
let addressCountrySubdivisionName = '';
let positionLat = '';
let positionLon = '';
let viewportTopLeftPointLat = '';
let viewportTopLeftPointLon = '';
let viewportBtmRightPointLat = '';
let viewportBtmRightPointLon = '';
let j = 0;
let countJ = 0;
const summaryQuery = jsonResponse.stringOf('summary.query');
const summaryQueryType = jsonResponse.stringOf('summary.queryType');
const summaryQueryTime = jsonResponse.intOf('summary.queryTime');
const summaryNumResults = jsonResponse.intOf('summary.numResults');
const summaryOffset = jsonResponse.intOf('summary.offset');
const summaryTotalResults = jsonResponse.intOf('summary.totalResults');
const summaryFuzzyLevel = jsonResponse.intOf('summary.fuzzyLevel');
i = 0;
const countI = jsonResponse.sizeOfArray('results');
while (i < countI) {
jsonResponse.i = i;
vType = jsonResponse.stringOf('results[i].type');
id = jsonResponse.stringOf('results[i].id');
score = jsonResponse.stringOf('results[i].score');
addressStreetNumber = jsonResponse.stringOf('results[i].address.streetNumber');
addressStreetName = jsonResponse.stringOf('results[i].address.streetName');
addressMunicipalitySubdivision = jsonResponse.stringOf('results[i].address.municipalitySubdivision');
addressMunicipality = jsonResponse.stringOf('results[i].address.municipality');
addressCountrySecondarySubdivision = jsonResponse.stringOf('results[i].address.countrySecondarySubdivision');
addressCountryTertiarySubdivision = jsonResponse.stringOf('results[i].address.countryTertiarySubdivision');
addressCountrySubdivision = jsonResponse.stringOf('results[i].address.countrySubdivision');
addressPostalCode = jsonResponse.stringOf('results[i].address.postalCode');
addressExtendedPostalCode = jsonResponse.stringOf('results[i].address.extendedPostalCode');
addressCountryCode = jsonResponse.stringOf('results[i].address.countryCode');
addressCountry = jsonResponse.stringOf('results[i].address.country');
addressCountryCodeISO3 = jsonResponse.stringOf('results[i].address.countryCodeISO3');
addressFreeformAddress = jsonResponse.stringOf('results[i].address.freeformAddress');
addressCountrySubdivisionName = jsonResponse.stringOf('results[i].address.countrySubdivisionName');
positionLat = jsonResponse.stringOf('results[i].position.lat');
positionLon = jsonResponse.stringOf('results[i].position.lon');
viewportTopLeftPointLat = jsonResponse.stringOf('results[i].viewport.topLeftPoint.lat');
viewportTopLeftPointLon = jsonResponse.stringOf('results[i].viewport.topLeftPoint.lon');
viewportBtmRightPointLat = jsonResponse.stringOf('results[i].viewport.btmRightPoint.lat');
viewportBtmRightPointLon = jsonResponse.stringOf('results[i].viewport.btmRightPoint.lon');
j = 0;
countJ = jsonResponse.sizeOfArray('results[i].entryPoints');
while (j < countJ) {
jsonResponse.j = j;
vType = jsonResponse.stringOf('results[i].entryPoints[j].type');
positionLat = jsonResponse.stringOf('results[i].entryPoints[j].position.lat');
positionLon = jsonResponse.stringOf('results[i].entryPoints[j].position.lon');
j++;
}
i++;
}
}