Azure Maps Search service includes API that offers various capabilities to help developers to search addresses, places, business listings by name or category, and other geographic information. For example, Search Fuzzy allows users to search for an address or Point of Interest (POI).
This article explains how to apply sound practices when you call data from Azure Maps Search service. You'll learn how to:
You can use any API development environment such as Postman or bruno to run the HTTP request samples shown in this article or to build REST calls.
Best practices to geocode addresses
When you search for a full or partial address by using Azure Maps Search service, the API reads keywords from your search query. Then it returns the longitude and latitude coordinates of the address. This process is called geocoding.
The ability to geocode in a country/region depends on the availability of road data and the precision of the geocoding service. For more information about Azure Maps geocoding capabilities by country or region, see Geocoding coverage.
Limit search results
Azure Maps Search API can help you limit search results appropriately. You limit results so that you can display relevant data to your users.
Note
The search APIs support more parameters than just the ones that this article discusses.
Geobiased search results
To geobias results to the relevant area for your user, always add as many location details as possible. You might want to restrict the search results by specifying some input types:
Set the countrySet parameter. You can set it to US,FR, for example. By default, the API searches the entire world, so it can return unnecessary results. If your query has no countrySet parameter, then the search might return inaccurate results. For example, a search for a city named Bellevue returns results from the USA and France because both countries/regions contain a city named Bellevue.
You can use the btmRight and topleft parameters to set the bounding box. These parameters restrict the search to a specific area on the map.
To influence the area of relevance for the results, define the lat and lon coordinate parameters. Use the radius parameter to set the radius of the search area.
Fuzzy search parameters
We recommend that you use Search Fuzzy when you don't know your user inputs for a search query. For example, input from the user could be an address or the type of Point of Interest (POI), like shopping mall. The API combines POI searching and geocoding into a canonical single-line search:
The minFuzzyLevel and maxFuzzyLevel parameters help return relevant matches even when query parameters don't exactly match the information that the user wants. To maximize performance and reduce unusual results, set search queries to defaults of minFuzzyLevel=1 and maxFuzzyLevel=2.
For example, when the maxFuzzyLevel parameter is set to 2, the search term restrant is matched to restaurant. You can override the default fuzzy levels when you need to.
Use the idxSet parameter to prioritize the exact set of result types. To prioritize an exact set of results, you can submit a comma-separated list of indexes. In your list, the item order doesn't matter. Azure Maps supports the following indexes:
Addr - Address ranges: Address points that are interpolated from the beginning and end of the street. These points are represented as address ranges.
Geo - Geographies: Administrative divisions of land. A geography can be a country/region, state, or city, for example.
PAD - Point addresses: Addresses that include a street name and number. Point addresses can be found in an index. An example is Soquel Dr 2501. A point address provides the highest level of accuracy available for addresses.
POI - Points of interest: Points on a map that are considered to be worth attention or that might be interesting. Search Address doesn't return POIs.
Str - Streets: Streets on the map.
XStr - Cross streets or intersections: Junctions or places where two streets intersect.
Usage examples
idxSet=POI - Search POIs only.
idxSet=PAD,Addr - Search addresses only. PAD indicates the point address, and Addr indicates the address range.
Reverse-geocode and filter for a geography entity type
When you do a reverse-geocode search using Search Address Reverse, the service can return polygons for administrative areas. For example, you might want to fetch the area polygon for a city. To narrow the search to specific geography entity types, include the entityType parameter in your requests.
The resulting response contains the geography ID and the entity type that was matched. If you provide more than one entity, then the endpoint returns the smallest entity available. You can use the returned geometry ID to get the geography's geometry through the Search Polygon service.
Use the language parameter to set the language for the returned search results. If the request doesn't set the language, then by default Search service uses the most common language in the country or region. When no data is available in the specified language, the default language is used.
To find more matches for partial queries, set the typeahead parameter to true. This query is interpreted as a partial input, and the search enters predictive mode. If you don't set the typeahead parameter to true, then the service assumes that all relevant information has been passed in.
In the following sample query, the Search Address service is queried for Microso. Here, the typeahead parameter set to true. The response shows that the search service interpreted the query as partial query. The response contains results for an automatically suggested query.
To find cross street addresses, you must encode the URI to handle special characters in the address. Consider this address example: 1st Avenue & Union Street, Seattle. Here, encode the ampersand character (&) before you send the request.
We recommend that you encode character data in a URI. In a URI, you encode all characters by using a percentage sign (%) and a two-character hexadecimal value that corresponds to the characters' UTF-8 code.
In a POI search, you can request POI results by name. For example, you can search for a business by name.
We strongly recommend that you use the countrySet parameter to specify countries/regions where your application needs coverage. The default behavior is to search the entire world. This broad search might return unnecessary results, and the search might take a long time.
Brand search
To improve the relevance of the results and the information in the response, a POI search response includes brand information. You can use this information to further to parse the response.
In a request, you can submit a comma-separated list of brand names. Use the list to restrict the results to specific brands by setting the brandSet parameter. In your list, item order doesn't matter. When you provide multiple brand lists, the results that are returned must belong to at least one of your lists.
To explore brand searching, let's make a POI category search request. In the following example, we look for gas stations near the Microsoft campus in Redmond, Washington. The response shows brand information for each POI that was returned.
By using the Search POI API, you can look for airports by using their official code. For example, you can use SEA to find the Seattle-Tacoma International Airport:
To retrieve POI results around a specific location, you can try using Search Nearby. The endpoint returns only POI results. It doesn't take in a search query parameter.
To limit the results, we recommend that you set the radius.
Understanding the responses
Let's find an address in Seattle by making an address-search request to the Azure Maps Search service. In the following request URL, we set the countrySet parameter to US to search for the address in the USA.
Point Address: Points on a map that have a specific address with a street name and number. Point Address provides the highest level of accuracy for addresses.
Address Range: The range of address points that are interpolated from the beginning and end of the street.
Geography: Areas on a map that represent administrative divisions of a land, for example, country/region, state, or city.
POI: Points on a map that are worth attention and that might be interesting.
Street: Streets on the map. Addresses are resolved to the latitude and longitude coordinates of the street that contains the address. The house number might not be processed.
Cross Street: Intersections. Cross streets represent junctions where two streets intersect.
Response
Let's look at the response structure. In the response that follows, the types of the result objects are different. If you look carefully, you see three types of result objects:
Point Address
Street
Cross Street
Notice that the address search doesn't return POIs.
The Score parameter for each response object indicates how the matching score relates to the scores of other objects in the same response. For more information about response object parameters, see Get Search Address.
A response type of Geometry can include the geometry ID that's returned in the dataSources object under geometry and id. For example, you can use the Search Polygon service to request the geometry data in a GeoJSON format. By using this format, you can get a city or airport outline for a set of entities. You can then use this boundary data to Set up a geofence or Search POIs inside the geometry.
Responses for Search Address or the Search Fuzzy can include the geometry ID that's returned in the dataSources object under geometry and id:
"dataSources": {
"geometry": {
"id": "00005557-4100-3c00-0000-000059690938" // The geometry ID is returned in the dataSources object under "geometry" and "id".
}
}
Use more advanced features of Azure AI Search to improve your existing search solutions. Learn how to change the ranking on documents, boost the most important terms to your organization, and allow searching in multiple languages.