azure-maps-search-dotnet
microsoft/skills
Azure Maps의 위치 기반 서비스를 .NET 애플리케이션에 통합하여 지오코딩, 경로 안내, 렌더링, 위치 파악 및 기상 데이터를 활용할 수 있습니다.
...모든 것을 확장하십시오Azure Maps (.NET)
위치 기반 서비스(지오코딩, 경로 안내, 렌더링, 지리적 위치 파악, 날씨 정보)를 제공하는 .NET용 Azure Maps SDK.
설치
# 검색 (지오코딩, 역지오코딩)
dotnet add package Azure.Maps.Search --prerelease
# 경로 안내 (길 찾기, 경로 매트릭스)
dotnet add package Azure.Maps.Routing --prerelease
# 렌더링 (지도 타일, 정적 이미지)
dotnet add package Azure.Maps.Rendering --prerelease
# 지리적 위치 파악 (IP 주소 기반 위치 파악)
dotnet add package Azure.Maps.Geolocation --prerelease
# 날씨
dotnet add package Azure.Maps.Weather --prerelease
# 리소스 관리 (계정 관리, SAS 토큰)
dotnet add package Azure.ResourceManager.Maps --prerelease
# 인증에 필수
dotnet add package Azure.Identity
현재 버전:
Azure.Maps.Search: v2.0.0-beta.5Azure.Maps.Routing: v1.0.0-beta.4Azure.Maps.Rendering: v2.0.0-beta.1Azure.Maps.Geolocation: v1.0.0-beta.3Azure.ResourceManager.Maps: v1.1.0-beta.2
환경 변수
AZURE_MAPS_SUBSCRIPTION_KEY= # AzureKeyCredential 인증 시에만 필요
AZURE_MAPS_CLIENT_ID= # 필수: Azure Maps 클라이언트 ID
AZURE_TOKEN_CREDENTIALS=prod # 프로덕션 환경에서 DefaultAzureCredential을 사용하는 경우에만 필요
인증
구독 키(공유 키)
using Azure;
using Azure.Maps.Search;
var subscriptionKey = Environment.GetEnvironmentVariable("AZURE_MAPS_SUBSCRIPTION_KEY");
var credential = new AzureKeyCredential(subscriptionKey);
var client = new MapsSearchClient(credential);
Microsoft Entra 토큰 자격 증명
using Azure.Identity;
using Azure.Maps.Search;
// 로컬 개발 환경: DefaultAzureCredential. 프로덕션: AZURE_TOKEN_CREDENTIALS=prod 또는 AZURE_TOKEN_CREDENTIALS=로 설정
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// 또는 프로덕션 환경에서 특정 자격 증명을 직접 사용:
// https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes 참조
// var credential = new ManagedIdentityCredential();
var clientId = Environment.GetEnvironmentVariable("AZURE_MAPS_CLIENT_ID");
var client = new MapsSearchClient(credential, clientId);
공유 액세스 서명(SAS)
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Maps;
using Azure.ResourceManager.Maps.Models;
using Azure.Maps.Search;
// Azure Resource Manager로 인증
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Maps 계정 리소스 가져오기
ResourceIdentifier mapsAccountResourceId = MapsAccountResource.CreateResourceIdentifier(
subscriptionId, resourceGroupName, accountName);
MapsAccountResource mapsAccount = armClient.GetMapsAccountResource(mapsAccountResourceId);
// SAS 토큰 생성
MapsAccountSasContent sasContent = new MapsAccountSasContent(
MapsSigningKey.PrimaryKey,
principalId,
maxRatePerSecond: 500,
start: DateTime.UtcNow.ToString("O"),
expiry: DateTime.UtcNow.AddDays(1).ToString("O"));
를 반환하는 Response sas = mapsAccount.GetSas(sasContent);
// SAS 토큰으로 클라이언트 생성
var sasCredential = new AzureSasCredential(sas.Value.AccountSasToken);
var client = new MapsSearchClient(sasCredential);
클라이언트 계층 구조
Azure.Maps.Search
└── MapsSearchClient
├── GetGeocoding() → 주소 지오코딩
├── GetGeocodingBatch() → 일괄 지오코딩
├── GetReverseGeocoding() → 좌표에서 주소로 변환
├── GetReverseGeocodingBatch() → 일괄 역지오코딩
└── GetPolygon() → 경계 다각형 가져오기
Azure.Maps.Routing
└── MapsRoutingClient
├── GetDirections() → 경로 안내
├── GetImmediateRouteMatrix() → 경로 매트릭스 (동기, ≤100)
├── GetRouteMatrix() → 경로 매트릭스 (비동기, ≤700)
└── GetRouteRange() → 등시간/도달 가능 범위
Azure.Maps.Rendering
└── MapsRenderingClient
├── GetMapTile() → 지도 타일
├── GetMapStaticImage() → 정적 지도 이미지
└── GetCopyrightCaption() → 저작권 정보
Azure.Maps.Geolocation
└── MapsGeolocationClient
└── GetCountryCode() → IP 기반 국가/지역 정보
Azure.Maps.Weather
└── MapsWeatherClient
├── GetCurrentWeatherConditions() → 현재 날씨
├── GetDailyForecast() → 일일 예보
├── GetHourlyForecast() → 시간별 예보
└── GetSevereWeatherAlerts() → 기상 경보
핵심 워크플로
1. 지오코딩 (주소를 좌표로 변환)
using Azure;
using Azure.Maps.Search;
var credential = new AzureKeyCredential(subscriptionKey);
var client = new MapsSearchClient(credential);
Response result = client.GetGeocoding("1 Microsoft Way, Redmond, WA 98052");
foreach (var feature in result.Value.Features)
{
Console.WriteLine($"좌표: {string.Join(",", feature.Geometry.Coordinates)}");
Console.WriteLine($"주소: {feature.Properties.Address.FormattedAddress}");
Console.WriteLine($"신뢰도: {feature.Properties.Confidence}");
}
2. 일괄 지오코딩
using Azure.Maps.Search.Models.Queries;
List queries = new List
{
new GeocodingQuery() { Query = "400 Broad St, Seattle, WA" },
new GeocodingQuery() { Query = "1 Microsoft Way, Redmond, WA" },
new GeocodingQuery() { AddressLine = "Space Needle", Top = 1 },
};
응답 results = client.GetGeocodingBatch(queries);
foreach (var batchItem in results.Value.BatchItems)
{
foreach (var feature in batchItem.Features)
{
Console.WriteLine($"좌표: {string.Join(",", feature.Geometry.Coordinates)}");
}
}
3. 역지오코딩 (좌표에서 주소로)
using Azure.Core.GeoJson;
GeoPosition 좌표 = new GeoPosition(-122.138685, 47.6305637);
Response 결과 = client.GetReverseGeocoding(좌표);
foreach (var feature in result.Value.Features)
{
Console.WriteLine($"주소: {feature.Properties.Address.FormattedAddress}");
Console.WriteLine($"지역: {feature.Properties.Address.Locality}");
}
4. 경계 다각형 가져오기
using Azure.Maps.Search.Models;
GetPolygonOptions options = new GetPolygonOptions()
{
Coordinates = new GeoPosition(-122.204141, 47.61256),
ResultType = BoundaryResultTypeEnum.Locality,
Resolution = ResolutionEnum.Small,
};
Response result = client.GetPolygon(options);
Console.WriteLine($"경계 저작권: {result.Value.Properties?.Copyright}");
Console.WriteLine($"다각형 개수: {result.Value.Geometry.Count}");
5. 경로 안내
using Azure;
using Azure.Core.GeoJson;
using Azure.Maps.Routing;
using Azure.Maps.Routing.Models;
var client = new MapsRoutingClient(new AzureKeyCredential(subscriptionKey));
List routePoints = new List()
{
new GeoPosition(-122.34, 47.61), // 시애틀
new GeoPosition(-122.13, 47.64) // 레드몬드
};
RouteDirectionQuery query = new RouteDirectionQuery(routePoints);
Response result = client.GetDirections(query);
foreach (var route in result.Value.Routes)
{
Console.WriteLine($"거리: {route.Summary.LengthInMeters} 미터");
Console.WriteLine($"소요 시간: {route.Summary.TravelTimeDuration}");
foreach (RouteLeg leg in route.Legs)
{
Console.WriteLine($"구간 경유지: {leg.Points.Count}");
}
}
6. 옵션이 포함된 경로 안내
RouteDirectionOptions options = new RouteDirectionOptions()
{
RouteType = RouteType.Fastest,
UseTrafficData = true,
TravelMode = TravelMode.Bicycle,
Language = RoutingLanguage.EnglishUsa,
InstructionsType = RouteInstructionsType.Text,
};
RouteDirectionQuery query = new RouteDirectionQuery(routePoints)
{
RouteDirectionOptions = options
};
Response result = client.GetDirections(query);
7. 경로 매트릭스
RouteMatrixQuery routeMatrixQuery = new RouteMatrixQuery
{
Origins = new List()
{
new GeoPosition(-122.34, 47.61),
new GeoPosition(-122.13, 47.64)
},
Destinations = new List ()
{
new GeoPosition(-122.20, 47.62),
new GeoPosition(-122.40, 47.65)
},
};
// 동기식 (최대 100개의 경로 조합)
Response result = client.GetImmediateRouteMatrix(routeMatrixQuery);
foreach (var cell in result.Value.Matrix.SelectMany(row => row))
{
Console.WriteLine($"거리: {cell.Response?.RouteSummary?.LengthInMeters}");
Console.WriteLine($"소요 시간: {cell.Response?.RouteSummary?.TravelTimeDuration}");
}
// 비동기 (최대 700개의 경로 조합)
RouteMatrixOptions routeMatrixOptions = new RouteMatrixOptions(routeMatrixQuery)
{
TravelTimeType = TravelTimeType.All,
};
GetRouteMatrixOperation asyncResult = client.GetRouteMatrix(WaitUntil.Completed, routeMatrixOptions);
8. 경로 범위 (등시간선)
RouteRangeOptions options = new RouteRangeOptions(-122.34, 47.61)
{
TimeBudget = new TimeSpan(0, 20, 0) // 20분
};
Response result = client.GetRouteRange(options);
// result.Value.ReachableRange에 다각형이 포함됩니다.
Console.WriteLine($"경계점: {result.Value.ReachableRange.Boundary.Count}");
9. 지도 타일 가져오기
using Azure;
using Azure.Maps.Rendering;
var client = new MapsRenderingClient(new AzureKeyCredential(subscriptionKey));
int zoom = 10;
int tileSize = 256;
// 좌표를 타일 인덱스로 변환
MapTileIndex tileIndex = MapsRenderingClient.PositionToTileXY(
new GeoPosition(13.3854, 52.517), zoom, tileSize);
// 지도 타일 가져오기
GetMapTileOptions options = new GetMapTileOptions(
MapTileSetId.MicrosoftImagery,
new MapTileIndex(tileIndex.X, tileIndex.Y, zoom)
);
Response mapTile = client.GetMapTile(options);
// 파일로 저장
using (FileStream fileStream = File.Create("./MapTile.png"))
{
mapTile.Value.CopyTo(fileStream);
}
10. IP 기반 위치 정보
using System.Net;
using Azure;
using Azure.Maps.Geolocation;
var client = new MapsGeolocationClient(new AzureKeyCredential(subscriptionKey));
IPAddress ipAddress = IPAddress.Parse("2001:4898:80e8:b::189");
Response result = client.GetCountryCode(ipAddress);
Console.WriteLine($"국가 ISO 코드: {result.Value.IsoCode}");
11. 현재 날씨
using Azure;
using Azure.Core.GeoJson;
using Azure.Maps.Weather;
var client = new MapsWeatherClient(new AzureKeyCredential(subscriptionKey));
var position = new GeoPosition(-122.13071, 47.64011);
var options = new GetCurrentWeatherConditionsOptions(position);
Response result = client.GetCurrentWeatherConditions(options);
foreach (var condition in result.Value.Results)
{
Console.WriteLine($"온도: {condition.Temperature.Value} {condition.Temperature.Unit}");
Console.WriteLine($"날씨: {condition.Phrase}");
Console.WriteLine($"습도: {condition.RelativeHumidity}%");
}
키 유형 참조
패키지 검색
| 유형 | 용도 |
|---|---|
MapsSearchClient |
검색 작업을 위한 주요 클라이언트 |
지오코딩 응답 |
지오코딩 결과 |
지오코딩 일괄 처리 응답 |
일괄 지오코딩 결과 |
지오코딩 쿼리 |
일괄 지오코딩 쿼리 |
역지오코딩 쿼리 |
일괄 역지오코딩 쿼리 |
GetPolygonOptions |
다각형 검색 옵션 |
경계 |
경계 다각형 결과 |
BoundaryResultTypeEnum |
경계 유형(지역, 행정구역 등) |
해상도 열거형 |
다각형 해상도 (Small, Medium, Large) |
경로 설정 패키지
| 유형 | 목적 |
|---|---|
MapsRoutingClient |
경로 탐색 작업을 위한 주요 클라이언트 |
경로방향조회 |
경로 안내 조회 |
경로 방향 옵션 |
경로 계산 옵션 |
경로 안내 |
경로 안내 결과 |
경로 구간 |
경로의 구간 |
경로 행렬 조회 |
경로 행렬 조회 |
경로 행렬 결과 |
경로 행렬 결과 |
경로 범위 옵션 |
등시간 구간 옵션 |
경로 범위 결과 |
등시간 결과 |
경로 유형 |
경로 유형 (가장 빠름, 가장 짧음, 친환경, 스릴 넘치는) |
TravelMode |
이동 수단(승용차, 트럭, 자전거, 도보) |
렌더링 패키지
| 유형 | 용도 |
|---|---|
MapsRenderingClient |
렌더링을 위한 메인 클라이언트 |
GetMapTileOptions |
지도 타일 옵션 |
MapTileIndex |
타일 좌표 (X, Y, 확대/축소) |
MapTileSetId |
타일 세트 식별자 |
일반적인 유형
| 유형 | 용도 |
|---|---|
GeoPosition |
지리적 위치 (경도, 위도) |
GeoBoundingBox |
지리적 영역의 경계 상자 |
모범 사례
- 프로덕션 환경에서는 Entra ID를 사용하십시오 — 구독 키보다 우선적으로 사용하십시오
- 일괄 처리 — 여러 주소에 대해 일괄 지오코딩을 사용하십시오
- 결과 캐싱 — 지오코딩 결과는 자주 변경되지 않습니다
- 적절한 타일 크기 사용 — 디스플레이에 따라 256 또는 512 픽셀
- 요율 제한 처리 — 지수적 백오프 구현
- 비동기 경로 행렬 사용 — 대규모 행렬 계산(100개 초과) 시
- 교통 데이터 고려 — 정확한 도착 예상 시간(ETA)을 위해
UseTrafficData = true로설정
오류 처리
try
{
Response result = client.GetGeocoding(address);
}
catch (RequestFailedException ex)
{
Console.WriteLine($"상태: {ex.Status}");
Console.WriteLine($"오류: {ex.Message}");
switch (ex.Status)
{
case 400:
// 유효하지 않은 요청 매개변수
break;
case 401:
// 인증 실패
break;
case 429:
// 요청 빈도 제한 - 백오프 구현
break;
}
}
관련 SDK
| SDK | 목적 | 설치 |
|---|---|---|
Azure.Maps.Search |
지오코딩, 검색 | dotnet add package Azure.Maps.Search --prerelease |
Azure.Maps.Routing |
경로 안내, 매트릭스 | dotnet add package Azure.Maps.Routing --prerelease |
Azure.Maps.Rendering |
지도 타일, 이미지 | dotnet add package Azure.Maps.Rendering --prerelease |
Azure.Maps.Geolocation |
IP 위치 정보 | dotnet add package Azure.Maps.Geolocation --prerelease |
Azure.Maps.Weather |
날씨 데이터 | dotnet add package Azure.Maps.Weather --prerelease |
Azure.ResourceManager.Maps |
계정 관리 | dotnet add package Azure.ResourceManager.Maps --prerelease |
참고 링크
| 리소스 | URL |
|---|---|
| Azure Maps 문서 | https://learn.microsoft.com/azure/azure-maps/ |
| 검색 API 참조 | https://learn.microsoft.com/dotnet/api/azure.maps.search |
| 경로 안내 API 참조 | https://learn.microsoft.com/dotnet/api/azure.maps.routing |
| GitHub 소스 | https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/maps |
| 가격 | https://azure.microsoft.com/pricing/details/azure-maps/ |
---
name: azure-maps-search-dotnet
description: Integrate Azure Maps location-based services into .NET applications for geocoding, routing, rendering, geolocation, and weather data.
license: MIT
---
# Azure Maps (.NET)
Azure Maps SDK for .NET providing location-based services: geocoding, routing, rendering, geolocation, and weather.
## Installation
```bash
# Search (geocoding, reverse geocoding)
dotnet add package Azure.Maps.Search --prerelease
# Routing (directions, route matrix)
dotnet add package Azure.Maps.Routing --prerelease
# Rendering (map tiles, static images)
dotnet add package Azure.Maps.Rendering --prerelease
# Geolocation (IP to location)
dotnet add package Azure.Maps.Geolocation --prerelease
# Weather
dotnet add package Azure.Maps.Weather --prerelease
# Resource Management (account management, SAS tokens)
dotnet add package Azure.ResourceManager.Maps --prerelease
# Required for authentication
dotnet add package Azure.Identity
```
**Current Versions**:
- `Azure.Maps.Search`: v2.0.0-beta.5
- `Azure.Maps.Routing`: v1.0.0-beta.4
- `Azure.Maps.Rendering`: v2.0.0-beta.1
- `Azure.Maps.Geolocation`: v1.0.0-beta.3
- `Azure.ResourceManager.Maps`: v1.1.0-beta.2
## Environment Variables
```bash
AZURE_MAPS_SUBSCRIPTION_KEY=<your-subscription-key> # Only required for AzureKeyCredential auth
AZURE_MAPS_CLIENT_ID=<your-client-id> # Required: Azure Maps client ID
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
```
## Authentication
### Subscription Key (Shared Key)
```csharp
using Azure;
using Azure.Maps.Search;
var subscriptionKey = Environment.GetEnvironmentVariable("AZURE_MAPS_SUBSCRIPTION_KEY");
var credential = new AzureKeyCredential(subscriptionKey);
var client = new MapsSearchClient(credential);
```
### Microsoft Entra Token Credential
```csharp
using Azure.Identity;
using Azure.Maps.Search;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var clientId = Environment.GetEnvironmentVariable("AZURE_MAPS_CLIENT_ID");
var client = new MapsSearchClient(credential, clientId);
```
### Shared Access Signature (SAS)
```csharp
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Maps;
using Azure.ResourceManager.Maps.Models;
using Azure.Maps.Search;
// Authenticate with Azure Resource Manager
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Get Maps account resource
ResourceIdentifier mapsAccountResourceId = MapsAccountResource.CreateResourceIdentifier(
subscriptionId, resourceGroupName, accountName);
MapsAccountResource mapsAccount = armClient.GetMapsAccountResource(mapsAccountResourceId);
// Generate SAS token
MapsAccountSasContent sasContent = new MapsAccountSasContent(
MapsSigningKey.PrimaryKey,
principalId,
maxRatePerSecond: 500,
start: DateTime.UtcNow.ToString("O"),
expiry: DateTime.UtcNow.AddDays(1).ToString("O"));
Response<MapsAccountSasToken> sas = mapsAccount.GetSas(sasContent);
// Create client with SAS token
var sasCredential = new AzureSasCredential(sas.Value.AccountSasToken);
var client = new MapsSearchClient(sasCredential);
```
## Client Hierarchy
```
Azure.Maps.Search
└── MapsSearchClient
├── GetGeocoding() → Geocode addresses
├── GetGeocodingBatch() → Batch geocoding
├── GetReverseGeocoding() → Coordinates to address
├── GetReverseGeocodingBatch() → Batch reverse geocoding
└── GetPolygon() → Get boundary polygons
Azure.Maps.Routing
└── MapsRoutingClient
├── GetDirections() → Route directions
├── GetImmediateRouteMatrix() → Route matrix (sync, ≤100)
├── GetRouteMatrix() → Route matrix (async, ≤700)
└── GetRouteRange() → Isochrone/reachable range
Azure.Maps.Rendering
└── MapsRenderingClient
├── GetMapTile() → Map tiles
├── GetMapStaticImage() → Static map images
└── GetCopyrightCaption() → Copyright info
Azure.Maps.Geolocation
└── MapsGeolocationClient
└── GetCountryCode() → IP to country/region
Azure.Maps.Weather
└── MapsWeatherClient
├── GetCurrentWeatherConditions() → Current weather
├── GetDailyForecast() → Daily forecast
├── GetHourlyForecast() → Hourly forecast
└── GetSevereWeatherAlerts() → Weather alerts
```
## Core Workflows
### 1. Geocoding (Address to Coordinates)
```csharp
using Azure;
using Azure.Maps.Search;
var credential = new AzureKeyCredential(subscriptionKey);
var client = new MapsSearchClient(credential);
Response<GeocodingResponse> result = client.GetGeocoding("1 Microsoft Way, Redmond, WA 98052");
foreach (var feature in result.Value.Features)
{
Console.WriteLine($"Coordinates: {string.Join(",", feature.Geometry.Coordinates)}");
Console.WriteLine($"Address: {feature.Properties.Address.FormattedAddress}");
Console.WriteLine($"Confidence: {feature.Properties.Confidence}");
}
```
### 2. Batch Geocoding
```csharp
using Azure.Maps.Search.Models.Queries;
List<GeocodingQuery> queries = new List<GeocodingQuery>
{
new GeocodingQuery() { Query = "400 Broad St, Seattle, WA" },
new GeocodingQuery() { Query = "1 Microsoft Way, Redmond, WA" },
new GeocodingQuery() { AddressLine = "Space Needle", Top = 1 },
};
Response<GeocodingBatchResponse> results = client.GetGeocodingBatch(queries);
foreach (var batchItem in results.Value.BatchItems)
{
foreach (var feature in batchItem.Features)
{
Console.WriteLine($"Coordinates: {string.Join(",", feature.Geometry.Coordinates)}");
}
}
```
### 3. Reverse Geocoding (Coordinates to Address)
```csharp
using Azure.Core.GeoJson;
GeoPosition coordinates = new GeoPosition(-122.138685, 47.6305637);
Response<GeocodingResponse> result = client.GetReverseGeocoding(coordinates);
foreach (var feature in result.Value.Features)
{
Console.WriteLine($"Address: {feature.Properties.Address.FormattedAddress}");
Console.WriteLine($"Locality: {feature.Properties.Address.Locality}");
}
```
### 4. Get Boundary Polygon
```csharp
using Azure.Maps.Search.Models;
GetPolygonOptions options = new GetPolygonOptions()
{
Coordinates = new GeoPosition(-122.204141, 47.61256),
ResultType = BoundaryResultTypeEnum.Locality,
Resolution = ResolutionEnum.Small,
};
Response<Boundary> result = client.GetPolygon(options);
Console.WriteLine($"Boundary copyright: {result.Value.Properties?.Copyright}");
Console.WriteLine($"Polygon count: {result.Value.Geometry.Count}");
```
### 5. Route Directions
```csharp
using Azure;
using Azure.Core.GeoJson;
using Azure.Maps.Routing;
using Azure.Maps.Routing.Models;
var client = new MapsRoutingClient(new AzureKeyCredential(subscriptionKey));
List<GeoPosition> routePoints = new List<GeoPosition>()
{
new GeoPosition(-122.34, 47.61), // Seattle
new GeoPosition(-122.13, 47.64) // Redmond
};
RouteDirectionQuery query = new RouteDirectionQuery(routePoints);
Response<RouteDirections> result = client.GetDirections(query);
foreach (var route in result.Value.Routes)
{
Console.WriteLine($"Distance: {route.Summary.LengthInMeters} meters");
Console.WriteLine($"Duration: {route.Summary.TravelTimeDuration}");
foreach (RouteLeg leg in route.Legs)
{
Console.WriteLine($"Leg points: {leg.Points.Count}");
}
}
```
### 6. Route Directions with Options
```csharp
RouteDirectionOptions options = new RouteDirectionOptions()
{
RouteType = RouteType.Fastest,
UseTrafficData = true,
TravelMode = TravelMode.Bicycle,
Language = RoutingLanguage.EnglishUsa,
InstructionsType = RouteInstructionsType.Text,
};
RouteDirectionQuery query = new RouteDirectionQuery(routePoints)
{
RouteDirectionOptions = options
};
Response<RouteDirections> result = client.GetDirections(query);
```
### 7. Route Matrix
```csharp
RouteMatrixQuery routeMatrixQuery = new RouteMatrixQuery
{
Origins = new List<GeoPosition>()
{
new GeoPosition(-122.34, 47.61),
new GeoPosition(-122.13, 47.64)
},
Destinations = new List<GeoPosition>()
{
new GeoPosition(-122.20, 47.62),
new GeoPosition(-122.40, 47.65)
},
};
// Synchronous (up to 100 route combinations)
Response<RouteMatrixResult> result = client.GetImmediateRouteMatrix(routeMatrixQuery);
foreach (var cell in result.Value.Matrix.SelectMany(row => row))
{
Console.WriteLine($"Distance: {cell.Response?.RouteSummary?.LengthInMeters}");
Console.WriteLine($"Duration: {cell.Response?.RouteSummary?.TravelTimeDuration}");
}
// Asynchronous (up to 700 route combinations)
RouteMatrixOptions routeMatrixOptions = new RouteMatrixOptions(routeMatrixQuery)
{
TravelTimeType = TravelTimeType.All,
};
GetRouteMatrixOperation asyncResult = client.GetRouteMatrix(WaitUntil.Completed, routeMatrixOptions);
```
### 8. Route Range (Isochrone)
```csharp
RouteRangeOptions options = new RouteRangeOptions(-122.34, 47.61)
{
TimeBudget = new TimeSpan(0, 20, 0) // 20 minutes
};
Response<RouteRangeResult> result = client.GetRouteRange(options);
// result.Value.ReachableRange contains the polygon
Console.WriteLine($"Boundary points: {result.Value.ReachableRange.Boundary.Count}");
```
### 9. Get Map Tiles
```csharp
using Azure;
using Azure.Maps.Rendering;
var client = new MapsRenderingClient(new AzureKeyCredential(subscriptionKey));
int zoom = 10;
int tileSize = 256;
// Convert coordinates to tile index
MapTileIndex tileIndex = MapsRenderingClient.PositionToTileXY(
new GeoPosition(13.3854, 52.517), zoom, tileSize);
// Fetch map tile
GetMapTileOptions options = new GetMapTileOptions(
MapTileSetId.MicrosoftImagery,
new MapTileIndex(tileIndex.X, tileIndex.Y, zoom)
);
Response<Stream> mapTile = client.GetMapTile(options);
// Save to file
using (FileStream fileStream = File.Create("./MapTile.png"))
{
mapTile.Value.CopyTo(fileStream);
}
```
### 10. IP Geolocation
```csharp
using System.Net;
using Azure;
using Azure.Maps.Geolocation;
var client = new MapsGeolocationClient(new AzureKeyCredential(subscriptionKey));
IPAddress ipAddress = IPAddress.Parse("2001:4898:80e8:b::189");
Response<CountryRegionResult> result = client.GetCountryCode(ipAddress);
Console.WriteLine($"Country ISO Code: {result.Value.IsoCode}");
```
### 11. Current Weather
```csharp
using Azure;
using Azure.Core.GeoJson;
using Azure.Maps.Weather;
var client = new MapsWeatherClient(new AzureKeyCredential(subscriptionKey));
var position = new GeoPosition(-122.13071, 47.64011);
var options = new GetCurrentWeatherConditionsOptions(position);
Response<CurrentConditionsResult> result = client.GetCurrentWeatherConditions(options);
foreach (var condition in result.Value.Results)
{
Console.WriteLine($"Temperature: {condition.Temperature.Value} {condition.Temperature.Unit}");
Console.WriteLine($"Weather: {condition.Phrase}");
Console.WriteLine($"Humidity: {condition.RelativeHumidity}%");
}
```
## Key Types Reference
### Search Package
| Type | Purpose |
|------|---------|
| `MapsSearchClient` | Main client for search operations |
| `GeocodingResponse` | Geocoding result |
| `GeocodingBatchResponse` | Batch geocoding result |
| `GeocodingQuery` | Query for batch geocoding |
| `ReverseGeocodingQuery` | Query for batch reverse geocoding |
| `GetPolygonOptions` | Options for polygon retrieval |
| `Boundary` | Boundary polygon result |
| `BoundaryResultTypeEnum` | Boundary type (Locality, AdminDistrict, etc.) |
| `ResolutionEnum` | Polygon resolution (Small, Medium, Large) |
### Routing Package
| Type | Purpose |
|------|---------|
| `MapsRoutingClient` | Main client for routing operations |
| `RouteDirectionQuery` | Query for route directions |
| `RouteDirectionOptions` | Route calculation options |
| `RouteDirections` | Route directions result |
| `RouteLeg` | Segment of a route |
| `RouteMatrixQuery` | Query for route matrix |
| `RouteMatrixResult` | Route matrix result |
| `RouteRangeOptions` | Options for isochrone |
| `RouteRangeResult` | Isochrone result |
| `RouteType` | Route type (Fastest, Shortest, Eco, Thrilling) |
| `TravelMode` | Travel mode (Car, Truck, Bicycle, Pedestrian) |
### Rendering Package
| Type | Purpose |
|------|---------|
| `MapsRenderingClient` | Main client for rendering |
| `GetMapTileOptions` | Map tile options |
| `MapTileIndex` | Tile coordinates (X, Y, Zoom) |
| `MapTileSetId` | Tile set identifier |
### Common Types
| Type | Purpose |
|------|---------|
| `GeoPosition` | Geographic position (longitude, latitude) |
| `GeoBoundingBox` | Bounding box for geographic area |
## Best Practices
1. **Use Entra ID for production** — Prefer over subscription keys
2. **Batch operations** — Use batch geocoding for multiple addresses
3. **Cache results** — Geocoding results don't change frequently
4. **Use appropriate tile sizes** — 256 or 512 pixels based on display
5. **Handle rate limits** — Implement exponential backoff
6. **Use async route matrix** — For large matrix calculations (>100)
7. **Consider traffic data** — Set `UseTrafficData = true` for accurate ETAs
## Error Handling
```csharp
try
{
Response<GeocodingResponse> result = client.GetGeocoding(address);
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Status: {ex.Status}");
Console.WriteLine($"Error: {ex.Message}");
switch (ex.Status)
{
case 400:
// Invalid request parameters
break;
case 401:
// Authentication failed
break;
case 429:
// Rate limited - implement backoff
break;
}
}
```
## Related SDKs
| SDK | Purpose | Install |
|-----|---------|---------|
| `Azure.Maps.Search` | Geocoding, search | `dotnet add package Azure.Maps.Search --prerelease` |
| `Azure.Maps.Routing` | Directions, matrix | `dotnet add package Azure.Maps.Routing --prerelease` |
| `Azure.Maps.Rendering` | Map tiles, images | `dotnet add package Azure.Maps.Rendering --prerelease` |
| `Azure.Maps.Geolocation` | IP geolocation | `dotnet add package Azure.Maps.Geolocation --prerelease` |
| `Azure.Maps.Weather` | Weather data | `dotnet add package Azure.Maps.Weather --prerelease` |
| `Azure.ResourceManager.Maps` | Account management | `dotnet add package Azure.ResourceManager.Maps --prerelease` |
## Reference Links
| Resource | URL |
|----------|-----|
| Azure Maps Documentation | https://learn.microsoft.com/azure/azure-maps/ |
| Search API Reference | https://learn.microsoft.com/dotnet/api/azure.maps.search |
| Routing API Reference | https://learn.microsoft.com/dotnet/api/azure.maps.routing |
| GitHub Source | https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/maps |
| Pricing | https://azure.microsoft.com/pricing/details/azure-maps/ |
모든 파일
0개 파일azure-maps-search-dotnet 설치
스킬 파일을 다운로드한 후 .claude/skills/ 디렉터리에 압축을 풀어주세요.
ZIP 다운로드저장소를 클론하고 스킬 파일을 프로젝트에 복사하세요.
git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-dotnet/skills/azure-maps-search-dotnet # Copy SKILL.md to your .claude/skills/ directory
복사





집
