You are using the old reverse geocoding service, use the latest: https://learn.microsoft.com/en-us/rest/api/maps/search/get-reverse-geocoding?view=rest-maps-2025-01-01&tabs=HTTP
The latest should be nearly identical data as Bing Maps.
Note the API interface of the new version is very different. Some key things to modify in your code:
- "query" parameter becomes "coordinates" and the format it "longitude,latitude" (reverse of the old service).
- The response format is a GeoJSON Feature Collection which is very different format from previous version.
Here is a modified version of your code:
import requests
def get_address(latitude, longitude, subscription_key):
# Define the endpoint and parameters for the Azure Maps Reverse Geocoding API
endpoint = "https://atlas.microsoft.com/reverseGeocode"
params = {
'api-version': '2025-01-01',
'subscription-key': subscription_key,
'language': 'en-US',
'coordinates': f'{longitude},{latitude}'
}
# Make a request to the API
response = requests.get(endpoint, params=params)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
#print(data)
if data['features']:
# Extract the address from the response
address_info = data['features'][0]['properties']['address']
freeform_address = address_info.get('formattedAddress', 'Address not found')
#building_name = address_info.get('buildingName', 'Building name not found')
#print(f"Address: {freeform_address}")
#print(f"Building Name: {building_name}")
else:
print('Address not found')
else:
print('Error: Unable to fetch address')
return freeform_address
# Lattitude and longitude can be found from navigator.geolocation too
latitude = 17.967673
longitude = 79.487091
subscription_key = '<azuremapskey>' # Replace with your actual subscription key
freeform_address = get_address(latitude, longitude, subscription_key)
print(f"The address for latitude {latitude} and longitude {longitude} is: {freeform_address}")