In this post, we will look at how to use a variety of geocoding APIs to convert a street address into latitude and longitude and then use those values with UDMap. We will dynamically add markers to the map using Add-UDElement. UDMap is a component available in Universal Dashboard Premium.

Geocoding

Geocoding is the process of converting a street address into latitude and longitude. Universal Dashboard does not do this automatically. You can use a third-party API to do this for you. One such API is HERE. Among other offerings, they provide free Geocoding services via a REST API that you can call from PowerShell. The free tier provides 250,000 requests per month.

Another option that works in a very similar way is the Bing Maps Locations API. Like the HERE Technologies API, the Bing Maps Location API also offers a variety of Geocoding functions accessible via REST APIs. In order to use the Bing Maps Locations API, you will need to obtain a Bing Maps Key by creating an account, this is a quick and free process, however, free accounts are also limited in their usage but it is most likely flexible enough for most projects

Calling the Geocoding API

To call the geocode API, we can just use Invoke-RestMethod since they provide a REST service. Once we get the response back from the server, it will contain the latitude and longitude for the address entered. Once we have the latitude and longitude, we can use it with New-UDMap.

 

Calling the Bing Maps Location API

To call the Bing Maps Location API, we can also use Invoke-RestMethod to interact with a REST service. In this example, we will be utilizing the “Find a Location by Address” service: 

The Bing Maps Location API will have its own unique set of input parameters and outputs but in this example, we have achieved the same output as our previous example that we can use with New-UDMap.

 

Dynamically Adding Markers by Address to UDMap

Let’s take the geocode example and expand on it to integrate with New-UDMap. This example will provide a map with a text box that you can enter an address and button to click to add the marker to the map. Once the button is clicked, we will get the textbox’s value and geocode it to get the latitude and longitude. Finally, we will add the maker to a cluster marker layer within the map.

Add marker to cluster layer

Conclusion

In this post, we went through how to convert an address into latitude and longitude using geocoding so that you can use them in Universal Dashboard. You will need to obtain a Bing Maps API key and a HERE API key to use the script in this example.

To learn more about the Universal Dashboard Map control, click here.