How to make my Azure Map determine accurate location information for my mobile users

Jim Derry 146 Reputation points
2025-04-11T10:21:00.2966667+00:00

I use the Azure Map service in my SaaS application. Users do not get an accurate location returned when we try to determine their position

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
809 questions
{count} votes

Accepted answer
  1. rbrundritt 20,201 Reputation points Microsoft Employee
    2025-04-11T15:22:30.5333333+00:00

    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}")
    
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.