Azure.Maps.Search
1.0.0-beta.2
Prefix Reserved
See the version list below for details.
dotnet add package Azure.Maps.Search --version 1.0.0-beta.2
NuGet\Install-Package Azure.Maps.Search -Version 1.0.0-beta.2
<PackageReference Include="Azure.Maps.Search" Version="1.0.0-beta.2" />
paket add Azure.Maps.Search --version 1.0.0-beta.2
#r "nuget: Azure.Maps.Search, 1.0.0-beta.2"
// Install Azure.Maps.Search as a Cake Addin #addin nuget:?package=Azure.Maps.Search&version=1.0.0-beta.2&prerelease // Install Azure.Maps.Search as a Cake Tool #tool nuget:?package=Azure.Maps.Search&version=1.0.0-beta.2&prerelease
Azure Maps Search client library for .NET
Azure Maps Search is a library that can query for locations, points of interests or search within a geometric area.
Source code | API reference documentation | REST API reference documentation | Product documentation
Getting started
Install the package
Install the client library for .NET with NuGet:
dotnet add package Azure.Maps.Search --prerelease
Prerequisites
You must have an Azure subscription and Azure Maps account.
To create a new Azure Maps account, you can use the Azure Portal, Azure PowerShell, or the Azure CLI. Here's an example using the Azure CLI:
az maps account create --kind "Gen2" --account-name "myMapAccountName" --resource-group "<resource group>" --sku "G2"
Authenticate the client
There are 2 ways to authenticate the client: Shared key authentication and Azure AD.
Shared Key Authentication
- Go to Azure Maps account > Authentication tab
- Copy
Primary Key
orSecondary Key
under Shared Key Authentication section
// Create a SearchClient that will authenticate through Subscription Key (Shared key)
AzureKeyCredential credential = new AzureKeyCredential("<My Subscription Key>");
MapsSearchClient client = new MapsSearchClient(credential);
Azure AD Authentication
In order to interact with the Azure Maps service, you'll need to create an instance of the MapsSearchClient class. The Azure Identity library makes it easy to add Azure Active Directory support for authenticating Azure SDK clients with their corresponding Azure services.
To use AAD authentication, set TENANT_ID
, CLIENT_ID
, and CLIENT_SECRET
to environment variable and call DefaultAzureCredential()
method to get credential. CLIENT_ID
and CLIENT_SECRET
are the service principal ID and secret that can access Azure Maps account.
We also need Azure Maps Client ID which can get from Azure Maps page > Authentication tab > "Client ID" in Azure Active Directory Authentication section.
// Create a MapsSearchClient that will authenticate through AAD
DefaultAzureCredential credential = new DefaultAzureCredential();
string clientId = "<My Map Account Client Id>";
MapsSearchClient client = new MapsSearchClient(credential, clientId);
Key concepts
MapsSearchClient
is designed to:
- Communicate with Azure Maps endpoint to query addresses or points of locations
- Communicate with Azure Maps endpoint to request the geometry data such as a city or country outline for a set of entities
- Communicate with Azure Maps endpoint to perform a free form search inside a single geometry or many of them
Learn more by viewing our samples
Thread safety
We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.
Additional concepts
Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime
Examples
You can familiarize yourself with different APIs using our samples.
Example Get Polygons
// Get Addresses
Response<SearchAddressResult> searchResult = await client.SearchAddressAsync("Seattle");
// Extract geometry ids from addresses
string geometry0Id = searchResult.Value.Results[0].DataSources.Geometry.Id;
string geometry1Id = searchResult.Value.Results[1].DataSources.Geometry.Id;
// Extract position coordinates
GeoPosition positionCoordinates = searchResult.Value.Results[0].Position;
// Get polygons from geometry ids
PolygonResult polygonResponse = await client.GetPolygonsAsync(new[] { geometry0Id, geometry1Id });
// Get polygons objects
IReadOnlyList<PolygonObject> polygonList = polygonResponse.Polygons;
Example Fuzzy Search
Response<SearchAddressResult> fuzzySearchResponse = await client.FuzzySearchAsync("coffee", new FuzzySearchOptions
{
Coordinates = new GeoPosition(121.56, 25.04),
Language = SearchLanguage.EnglishUsa
});
// Print out the possible results
Console.WriteLine("The possible results for coffee shop:");
foreach (SearchAddressResultItem result in fuzzySearchResponse.Value.Results)
{
Console.WriteLine("Coordinate: {0}, Address: {1}",
result.Position, result.Address.FreeformAddress);
}
Example Reverse Search Cross Street Address
var reverseResult = await client.ReverseSearchCrossStreetAddressAsync(new ReverseSearchCrossStreetOptions
{
Coordinates = new GeoPosition(121.0, 24.0),
Language = SearchLanguage.EnglishUsa
});
Example Search Structured Address
var address = new StructuredAddress
{
CountryCode = "US",
StreetNumber = "15127",
StreetName = "NE 24th Street",
Municipality = "Redmond",
CountrySubdivision = "WA",
PostalCode = "98052"
};
Response<SearchAddressResult> searchResult = await client.SearchStructuredAddressAsync(address);
SearchAddressResultItem resultItem = searchResult.Value.Results[0];
Console.WriteLine("First result - Coordinate: {0}, Address: {1}",
resultItem.Position, resultItem.Address.FreeformAddress);
Example Search Inside Geometry
GeoPolygon sfPolygon = new GeoPolygon(new[]
{
new GeoPosition(-122.43576049804686, 37.752415234354402),
new GeoPosition(-122.4330139160, 37.706604725423119),
new GeoPosition(-122.36434936523438, 37.712059855877314),
new GeoPosition(-122.43576049804686, 37.7524152343544)
});
GeoPolygon taipeiPolygon = new GeoPolygon(new[]
{
new GeoPosition(121.56, 25.04),
new GeoPosition(121.565, 25.04),
new GeoPosition(121.565, 25.045),
new GeoPosition(121.56, 25.045),
new GeoPosition(121.56, 25.04)
});
// Search coffee shop in Both polygons, return results in en-US
Response<SearchAddressResult> searchResponse = await client.SearchInsideGeometryAsync("coffee", new GeoCollection(new[] { sfPolygon, taipeiPolygon }), new SearchInsideGeometryOptions
{
Language = SearchLanguage.EnglishUsa
});
// Get Taipei Cafe and San Francisco cafe and print first place
SearchAddressResultItem taipeiCafe = searchResponse.Value.Results.Where(addressItem => addressItem.SearchAddressResultType == "POI" && addressItem.Address.Municipality == "Taipei City").First();
SearchAddressResultItem sfCafe = searchResponse.Value.Results.Where(addressItem => addressItem.SearchAddressResultType == "POI" && addressItem.Address.Municipality == "San Francisco").First();
Console.WriteLine("Possible Coffee shop in the Polygons:");
Console.WriteLine("Coffee shop address in Taipei: {0}", taipeiCafe.Address.FreeformAddress);
Console.WriteLine("Coffee shop address in San Francisco: {0}", sfCafe.Address.FreeformAddress);
Example Search Address
Response<SearchAddressResult> searchResult = await client.SearchAddressAsync("Seattle");
SearchAddressResultItem resultItem = searchResult.Value.Results[0];
Console.WriteLine("First result - Coordinate: {0}, Address: {1}",
resultItem.Position, resultItem.Address.FreeformAddress);
Troubleshooting
General
When you interact with the Azure Maps Services, errors returned by the Language service correspond to the same HTTP status codes returned for REST API requests.
For example, if you try to search with invalid coordinates, a error is returned, indicating "Bad Request".400
Next steps
Contributing
See the CONTRIBUTING.md for details on building, testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <cla.microsoft.com>.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Azure.Core (>= 1.25.0)
- Azure.Maps.Common (>= 1.0.0-beta.2)
- System.Text.Json (>= 4.7.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Azure.Maps.Search:
Package | Downloads |
---|---|
AzureAI.Community.Microsoft.Semantic.Kernel.PlugIn.Web.BingMap
AzureAI.Community Microsoft Semantic Kernel.PlugIn.Bing |
|
AzureMapVisualizer
AzureLocationMapVisualizer is a .NET class library that enables developers to generate location-based images using Azure Maps. With this library, you can create beautiful and informative maps that are customized to fit your application's needs. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0-beta.4 | 2,596 | 9/30/2024 |
2.0.0-beta.3 | 724 | 9/23/2024 |
2.0.0-beta.2 | 5,728 | 8/13/2024 |
2.0.0-beta.1 | 103 | 8/12/2024 |
1.0.0-beta.5 | 29,195 | 5/10/2024 |
1.0.0-beta.4 | 157,451 | 7/13/2023 |
1.0.0-beta.3 | 44,505 | 11/11/2022 |
1.0.0-beta.2 | 12,606 | 10/13/2022 |
1.0.0-beta.1 | 15,789 | 9/9/2022 |