Address Validation in PowerApps using Azure Maps Service(Part 2)

Welcome back readers. As part of our previous post we have created the Azure Maps service which we are going to use in a PowerApps for quick search/validation of address. As part of this blog we are going to create a simple PowerApp which uses the Azure Maps Search API to quickly search for an address. Lets look at the steps to create a Canvas PowerApp.

Login into https://web.powerapps.com using valid credentials

clip_image010_thumb[1]

Once logged-in click to create a Canvas app. On successfully creation, drag three controls a

1. Textbox – used to enter the address for search.

2. Button – used to initiate the address search using azure maps search API.

3. ListBox – used to display the search results.

clip_image012_thumb[1]

Lets add a Microsoft Flow workflow on the button click. This flow can be used to send an request to the Azure Maps service . Lets go through the steps to create the Flow for PowerApp. Click the button and navigate to Action menu to add a Flow

clip_image014_thumb[1]

Click to create a new Flow

clip_image016_thumb[1]

Once the Flow Editor is opened, the PowerApps step is already added as a first step. As part of our example we need to pass the address search string as a parameter to the flow. For that we need use the “Ask in PowerApps” variable which will act as a required parameter which holds the address search string. I have initiated a variable and passed the “Ask in PowerApps” as the default value.

clip_image018_thumb[1]

In the next step I have initialized a second variable called “AddressResults” of type Array to store the search results.

clip_image020_thumb[1]

The next step is to send in a request to the Azure Maps service to search for the address. Using a HTTP step add the required information as shown below. Pass the “AddressText” variable value as a Query parameter value.

clip_image022_thumb[1]

As the results are in JSON format, I am trying to parse the JSON so that it will be easy to extract the data. So I have added the “Parse Json” step to parse the response body. You can build the schema by using “Use sample payload to generate schema” option and Perform a quick query in your browser and past the results to generate the schema. The details are provided in our previous post. Once the schema is generated move onto the next step.

clip_image024_thumb[1]

The next step is to extract the results. As response is an array of address matches, we have to use a loop step. Add the “Apply to Each” step and parse the results. As defined in my previous post, the response has results—>address—>freeformAddress within the JSON. So instead of sending the entire results response, I am extracting only the address information and formatting it into a JSON object to pass it on to the PowerApps. The weird part is PowerApps only supports responses in JSON format. Which is strange. I will try to dig deeper into this, but for now lets stick to the logic to send the required response as JSON. As shown below I am storing the result addresses to the “AddressResults” array variable.

clip_image026_thumb[1]

The next step is format the output as a JSON object and send in the Response as shown below

clip_image028_thumb[1]

Now our Flow is ready to perform a search using Azure Maps search API

clip_image030_thumb[1]

Once done add the newly created flow to the “OnSelect” event of the button.

clip_image032_thumb[1]

Call the flow on click of the button and capture the response within a Global Variable as shown below

clip_image034_thumb[1]

Set the ListBox source to the global variable as shown below

clip_image036_thumb[1]

and we are all set to do a final test.

FinalTest

Address Validation in PowerApps using Azure Maps Service(Part 1)

Microsoft cloud computing platform “Azure” has become one of the core offerings of Microsoft. In this blog post, I am going to elaborate how to perform address validation using Azure Maps. Azure Maps has many offerings like Search, Maps, Geocoding, Traffic, Routing & Time Zones. We are going to use the Azure Maps Search to validate an address entered within an PowerApp.

The initial step is to create the Azure Map service from Azure portal. Login into Azure Portal I.e., https://portal.azure.com either using trail account or an azure account. Search for “Azure Maps Accounts”

clip_image002

Select the valid Subscription & Resource Group. By default, the “S0” pricing tier is selected. For more details please refer to the azure pricing details Azure-Maps Pricing. Click “Create” to create the mapping services. It may take few minutes for the Azure services to be hosted.

clip_image004

Once the Azure Maps service is successfully provisioned, lets perform a quick check of the address search using the Location API’s. We need the subscription key to perform this search. Click on the Keys and copy the Primary Key

clip_image006

We are going to use Fuzzy Search as part of this example so as defined in the Microsoft Docs Site (https://docs.microsoft.com/en-us/azure/azure-maps/how-to-search-for-address) construct the URL as

https://atlas.microsoft.com/search/address/json?api-version=1.0&subscription-key={subscriptionkey}&countrySet=AUS&typeahead=TRUE&query=4 Freshwater Pl,southbank

Param Description Value
api-version Version of the location services 1.0
subscription-key The primary key of the service from azure <<key>>
countrySet Filter to target specific country. AUS
typeahead If the typeahead flag is set, the query will be interpreted as a partial input and the search will enter predictive mode TRUE
Query A comma separated string of address or latitude followed by longitude

For more details please refer Get Search Fuzzy link.

If successful, it should return list of probable address matches in JSON format as

clip_image008

We have the Azure Maps Search API ready to validate/search addresses. As part of the Part 2 blog post we are going to leverage this service with in an PowerApp to perform a quick address validation.