Search code examples
azure-maps

Azure maps autocomplete - country and city only


I am writing an autocomplete service and want to get only country and city calling a Microsoft Azure service - with no addresses and POI or such.

I currently found Address Search where I would need to call https://atlas.microsoft.com/search/address, but it returns addresses, not cities and countries - which leads to many duplicates.

Plus, If I need to have a fixed number of auto complete options - say, 15 - it is going to require multiple calls to the service until I have all 15. On top of that, I will never know if there are more results for a typed partial country/city combination or not.

I don't want to use a fixed list as it needs maintenance.

I would not want to use another data provider for now, if it is possible to achieve with Azure.


Solution

  • This isn't supported yet, but is planned for the future. The closest that could be done now would be to use the https://learn.microsoft.com/en-us/rest/api/maps/search/getsearchaddressstructured service but it requires a country code to be specified, so you would only get cities for the specified country. For example, passing in new as the municipality as done in the following query:

    https://atlas.microsoft.com/search/address/structured/json?api-version=1&municipality=new&countryCode=US&subscription-key=<Your_Key>
    

    will return the following city results:

    • New York
    • New Orleans
    • New Braunfels
    • New Port Richey
    • New Bern
    • New Haven
    • New Iberia
    • New Castle
    • New Bedford
    • New Albany

    Here is the raw response

    {
        "summary": {
            "query": "new",
            "queryType": "NON_NEAR",
            "queryTime": 23,
            "numResults": 10,
            "offset": 0,
            "totalResults": 998,
            "fuzzyLevel": 1
        },
        "results": [
            {
                "type": "Geography",
                "id": "US/GEO/p0/1167",
                "score": 2.6649377346,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New York",
                    "countrySubdivision": "NY",
                    "countrySubdivisionName": "New York",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New York, NY"
                },
                "position": {
                    "lat": 40.71305,
                    "lon": -74.00723
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 40.9175,
                        "lon": -74.25564
                    },
                    "btmRightPoint": {
                        "lat": 40.49587,
                        "lon": -73.70027
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 40.9175,
                        "lon": -74.25564
                    },
                    "btmRightPoint": {
                        "lat": 40.49587,
                        "lon": -73.70027
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "d49d86a4-0f4b-45f2-b607-31a84d02af00"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/90711",
                "score": 2.5113995075,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Orleans",
                    "countrySecondarySubdivision": "Orleans",
                    "countrySubdivision": "LA",
                    "countrySubdivisionName": "Louisiana",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Orleans, LA"
                },
                "position": {
                    "lat": 29.95176,
                    "lon": -90.07462
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 30.21747,
                        "lon": -90.24051
                    },
                    "btmRightPoint": {
                        "lat": 29.86582,
                        "lon": -89.62506
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 30.21747,
                        "lon": -90.24051
                    },
                    "btmRightPoint": {
                        "lat": 29.86582,
                        "lon": -89.62506
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "0000554c-4100-3c00-0000-0000596a7628"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/103135",
                "score": 2.4384012222,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Braunfels",
                    "countrySubdivision": "TX",
                    "countrySubdivisionName": "Texas",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Braunfels, TX"
                },
                "position": {
                    "lat": 29.70988,
                    "lon": -98.11973
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 29.91293,
                        "lon": -98.34627
                    },
                    "btmRightPoint": {
                        "lat": 29.59298,
                        "lon": -97.9908
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 29.91293,
                        "lon": -98.34627
                    },
                    "btmRightPoint": {
                        "lat": 29.59298,
                        "lon": -97.9908
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "9d7bf985-115b-423a-979a-97cc093c3166"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/23041",
                "score": 2.4345231056,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Port Richey",
                    "countrySecondarySubdivision": "Pasco",
                    "countrySubdivision": "FL",
                    "countrySubdivisionName": "Florida",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Port Richey, FL"
                },
                "position": {
                    "lat": 28.2502,
                    "lon": -82.71408
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 28.33939,
                        "lon": -82.76461
                    },
                    "btmRightPoint": {
                        "lat": 28.17319,
                        "lon": -82.57478
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 28.33939,
                        "lon": -82.76461
                    },
                    "btmRightPoint": {
                        "lat": 28.17319,
                        "lon": -82.57478
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "00005546-3300-3c00-0000-000059a7e5e6"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/27115",
                "score": 2.414732933,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Bern",
                    "countrySecondarySubdivision": "Craven",
                    "countrySubdivision": "NC",
                    "countrySubdivisionName": "North Carolina",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Bern, NC"
                },
                "position": {
                    "lat": 35.10832,
                    "lon": -77.04612
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 35.28085,
                        "lon": -77.26051
                    },
                    "btmRightPoint": {
                        "lat": 34.90304,
                        "lon": -76.83165
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 35.28085,
                        "lon": -77.26051
                    },
                    "btmRightPoint": {
                        "lat": 34.90304,
                        "lon": -76.83165
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "00004e43-3300-3c00-0000-0000596be1d9"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/60622",
                "score": 2.4027762413,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Haven",
                    "countrySecondarySubdivision": "New Haven",
                    "countrySubdivision": "CT",
                    "countrySubdivisionName": "Connecticut",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Haven, CT"
                },
                "position": {
                    "lat": 41.30825,
                    "lon": -72.92416
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 41.35038,
                        "lon": -72.99807
                    },
                    "btmRightPoint": {
                        "lat": 41.2464,
                        "lon": -72.81773
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 41.35038,
                        "lon": -72.99807
                    },
                    "btmRightPoint": {
                        "lat": 41.2464,
                        "lon": -72.81773
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "00005543-5400-3c00-0000-0000596911a2"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/90802",
                "score": 2.4020097256,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Iberia",
                    "countrySecondarySubdivision": "Iberia",
                    "countrySubdivision": "LA",
                    "countrySubdivisionName": "Louisiana",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Iberia, LA"
                },
                "position": {
                    "lat": 30.00256,
                    "lon": -91.81698
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 30.12129,
                        "lon": -91.9944
                    },
                    "btmRightPoint": {
                        "lat": 29.73782,
                        "lon": -91.65921
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 30.12129,
                        "lon": -91.9944
                    },
                    "btmRightPoint": {
                        "lat": 29.73782,
                        "lon": -91.65921
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "0000554c-4100-3c00-0000-00005968eae5"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/61589",
                "score": 2.3937933445,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Castle",
                    "countrySecondarySubdivision": "New Castle",
                    "countrySubdivision": "DE",
                    "countrySubdivisionName": "Delaware",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Castle, DE"
                },
                "position": {
                    "lat": 39.66066,
                    "lon": -75.56184
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 39.7245,
                        "lon": -75.66496
                    },
                    "btmRightPoint": {
                        "lat": 39.55219,
                        "lon": -75.50945
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 39.7245,
                        "lon": -75.66496
                    },
                    "btmRightPoint": {
                        "lat": 39.55219,
                        "lon": -75.50945
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "00005544-4500-3c00-0000-000059685073"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/36482",
                "score": 2.3928732872,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Bedford",
                    "countrySecondarySubdivision": "Bristol",
                    "countrySubdivision": "MA",
                    "countrySubdivisionName": "Massachusetts",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Bedford, MA"
                },
                "position": {
                    "lat": 41.63405,
                    "lon": -70.92766
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 41.74525,
                        "lon": -70.97843
                    },
                    "btmRightPoint": {
                        "lat": 41.58185,
                        "lon": -70.87872
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 41.74525,
                        "lon": -70.97843
                    },
                    "btmRightPoint": {
                        "lat": 41.58185,
                        "lon": -70.87872
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "0000554d-4100-3c00-0000-00005969fc6d"
                    }
                }
            },
            {
                "type": "Geography",
                "id": "US/GEO/p0/12185",
                "score": 2.3897461891,
                "entityType": "Municipality",
                "address": {
                    "municipality": "New Albany",
                    "countrySecondarySubdivision": "Floyd",
                    "countrySubdivision": "IN",
                    "countrySubdivisionName": "Indiana",
                    "countryCode": "US",
                    "country": "United States",
                    "countryCodeISO3": "USA",
                    "freeformAddress": "New Albany, IN"
                },
                "position": {
                    "lat": 38.28351,
                    "lon": -85.823
                },
                "viewport": {
                    "topLeftPoint": {
                        "lat": 38.40435,
                        "lon": -85.8853
                    },
                    "btmRightPoint": {
                        "lat": 38.22944,
                        "lon": -85.76089
                    }
                },
                "boundingBox": {
                    "topLeftPoint": {
                        "lat": 38.40435,
                        "lon": -85.8853
                    },
                    "btmRightPoint": {
                        "lat": 38.22944,
                        "lon": -85.76089
                    }
                },
                "dataSources": {
                    "geometry": {
                        "id": "00005549-4e00-3c00-0000-0000596b63cf"
                    }
                }
            }
        ]
    }