Geocoding with Microsoft’s Azure Maps

API’s are getting more and more important as some (maybe the majority?) of GIS users don’t want to handle large datasets, don’t want to care about addresses and geo-coordinates, don’t want to create an own routing algorithm… As most of you might use Google, OSM or HERE for geocoding purposes I would like to introduce Azure Maps for this as well.

Azure Maps

We need to admit: No one is using Bing, am I right? No, seriously: Microsoft definitely missed the cloud computing and mapping developments in the past. Personally, I don’t know anyone using Bing Maps / Azure Maps at all. Yet, the recent changes in the pricing scheme for Google Maps Services might reshape the market a bit. So how do we use Azure Maps for, let’s say, geocoding.

The API Subscription

To use the geocoding service from Azure Maps you first need to create an Azure Maps account after you created an Microsoft Azure account. And yes, you will need a credit card already. And no, you can’t use the same payment details for two different subscriptions ;-).
Azure Mpas creation screen
Azure Maps Account creation in Azure Portal
For simple geocoding you will be fine with a S0 subscription which will give cost you €0.422 per 1,000 transactions (/geocodes). This price is well above the included transactions of a Freemium subscription at HERE. Once you have registered for the API you can use you subscription-key:
subscription keys at Azure Maps
subscription keys at Azure Maps

The Python Code

I don’t want to go too far with processing and plugins but want to share the simple code for requesting the API, getting the found address as well as some quality indicator and the latitude/longitude of course:
import requests, json
from qgis.core import QgsField, QgsFeature
from PyQt5.QtCore import QVariant
query = r'Mörikestraße 2, 06862 Dessau-Roßlau'
key = "put you fancy Primary Key here"
r = requests.get('' + key + '&query=' + query)
Now, as the query is set and send, we will deal with the response. But first, let’s create a layer for the result:
layer = QgsVectorLayer(
Our result will have some more “hits” as well as additional attributes but we will only use the one with the largest score and most important attributes:
fet = QgsFeature()

pr = layer.dataProvider()
As you can see, we got some results here:
geocoding results for the Azure Maps API
geocoding results for the Azure Maps API
In this example we used the “fuzzy search” approach. if you have a defined address structure, you might also want to try out the structured search or only “address search”. Fortunately, especially the address search uses a similar result schema, so you could easily change the above script and use:
r = requests.get('' + key + '&query=' + query)
Happy geocoding, everyone!
0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments