-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeocodingProvider.cs
More file actions
49 lines (43 loc) · 1.72 KB
/
GeocodingProvider.cs
File metadata and controls
49 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace AskForMasksCoreVue
{
using System.Threading.Tasks;
using AzureMapsToolkit;
using AzureMapsToolkit.Search;
using Microsoft.Azure.Cosmos.Spatial;
using Microsoft.Extensions.Configuration;
using Models;
public interface IGeocodingProvider
{
Task Locate(MaskRequest request);
Task<Point> GeocodeZip(string zipCode);
}
public class AzureMapsGeocodingProvider : IGeocodingProvider
{
private readonly AzureMapsServices _mapService;
public AzureMapsGeocodingProvider(IConfiguration config)
{
_mapService = new AzureMapsServices(config["AzureMapsKey"]);
}
public async Task Locate(MaskRequest request)
{
var searchAddressRequest = new SearchAddressRequest
{
Query = $"{request.Organization.AddressLine1} {request.Organization.City} {request.Organization.State} {request.Organization.ZipCode}",
Limit = 1,
CountrySet = "US"
};
var resp = await _mapService.GetSearchAddress(searchAddressRequest);
var lat = resp.Result.Results[0].Position.Lat;
var lon = resp.Result.Results[0].Position.Lon;
request.Organization.Geolocation = new Point(lon, lat);
}
public async Task<Point> GeocodeZip(string zipCode)
{
var searchAddressRequest = new SearchAddressRequest {Query = zipCode, Limit = 100, CountrySet = "US"};
var resp = await _mapService.GetSearchAddress(searchAddressRequest);
var lat = resp.Result.Results[0].Position.Lat;
var lon = resp.Result.Results[0].Position.Lon;
return new Point(lon, lat);
}
}
}