-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
MapsSearchClient.cs
1407 lines (1336 loc) · 103 KB
/
MapsSearchClient.cs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#nullable disable
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Core.GeoJson;
using Azure.Core.Pipeline;
using Azure.Maps;
using Azure.Maps.Common;
using Azure.Maps.Search.Models;
namespace Azure.Maps.Search
{
/// <summary> The Search service client. </summary>
public partial class MapsSearchClient
{
/// <summary> The HTTP pipeline for sending and receiving REST requests and responses. </summary>
private readonly HttpPipeline _pipeline;
/// <summary> The RestClient is used to access Route REST client. </summary>
internal SearchRestClient RestClient { get; }
/// <summary> The ClientDiagnostics is used to provide tracing support for the client library. </summary>
internal ClientDiagnostics _clientDiagnostics { get; }
/// <summary> Initializes a new instance of MapsSearchClient. </summary>
protected MapsSearchClient()
{
_clientDiagnostics = null;
_pipeline = null;
RestClient = null;
}
/// <summary> Initializes a new instance of MapsSearchClient. </summary>
/// <param name="credential"> Shared key credential used to authenticate to an Azure Maps Search Service. </param>
public MapsSearchClient(AzureKeyCredential credential)
{
Argument.AssertNotNull(credential, nameof(credential));
var endpoint = new Uri("https://atlas.microsoft.com");
var options = new MapsSearchClientOptions();
_clientDiagnostics = new ClientDiagnostics(options);
_pipeline = HttpPipelineBuilder.Build(options, new AzureKeyCredentialPolicy(credential, "subscription-key"));
RestClient = new SearchRestClient(_clientDiagnostics, _pipeline, endpoint, null, options.Version);
}
/// <summary> Initializes a new instance of MapsSearchClient. </summary>
/// <param name="credential"> Shared key credential used to authenticate to an Azure Maps Search Service. </param>
/// <param name="options"> The options for configuring the client. </param>
public MapsSearchClient(AzureKeyCredential credential, MapsSearchClientOptions options)
{
Argument.AssertNotNull(credential, nameof(credential));
var endpoint = options.Endpoint;
options ??= new MapsSearchClientOptions();
_clientDiagnostics = new ClientDiagnostics(options);
_pipeline = HttpPipelineBuilder.Build(options, new AzureKeyCredentialPolicy(credential, "subscription-key"));
RestClient = new SearchRestClient(_clientDiagnostics, _pipeline, endpoint, null, options.Version);
}
/// <summary> Initializes a new instance of MapsSearchClient. </summary>
/// <param name="credential"> A credential used to authenticate to an Azure Maps Search Service. </param>
/// <param name="clientId"> Specifies which account is intended for usage in conjunction with the Azure AD security model. It represents a unique ID for the Azure Maps account and can be retrieved from the Azure Maps management plane Account API. To use Azure AD security in Azure Maps see the following <see href="https://aka.ms/amauthdetails">articles</see> for guidance. </param>
public MapsSearchClient(TokenCredential credential, string clientId)
{
Argument.AssertNotNull(credential, nameof(credential));
var endpoint = new Uri("https://atlas.microsoft.com");
var options = new MapsSearchClientOptions();
_clientDiagnostics = new ClientDiagnostics(options);
string[] scopes = { "https://atlas.microsoft.com/.default" };
_pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, scopes), new AzureKeyCredentialPolicy(new AzureKeyCredential(clientId), "x-ms-client-id"));
RestClient = new SearchRestClient(_clientDiagnostics, _pipeline, endpoint, clientId, options.Version);
}
/// <summary> Initializes a new instance of MapsSearchClient. </summary>
/// <param name="credential"> A credential used to authenticate to an Azure Maps Search Service. </param>
/// <param name="clientId"> Specifies which account is intended for usage in conjunction with the Azure AD security model. It represents a unique ID for the Azure Maps account and can be retrieved from the Azure Maps management plane Account API. To use Azure AD security in Azure Maps see the following <see href="https://aka.ms/amauthdetails">articles</see> for guidance. </param>
/// <param name="options"> The options for configuring the client. </param>
public MapsSearchClient(TokenCredential credential, string clientId, MapsSearchClientOptions options)
{
Argument.AssertNotNull(credential, nameof(credential));
var endpoint = options.Endpoint;
options ??= new MapsSearchClientOptions();
_clientDiagnostics = new ClientDiagnostics(options);
string[] scopes = { "https://atlas.microsoft.com/.default" };
_pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, scopes), new AzureKeyCredentialPolicy(new AzureKeyCredential(clientId), "x-ms-client-id"));
RestClient = new SearchRestClient(_clientDiagnostics, _pipeline, endpoint, clientId, options.Version);
}
/// <summary> Initializes a new instance of MapsSearchClient. </summary>
/// <param name="credential"> The Shared Access Signature credential used to connect to Azure. This signature
/// can be constructed using the <see cref="AzureSasCredential"/>.</param>
public MapsSearchClient(AzureSasCredential credential)
{
Argument.AssertNotNull(credential, nameof(credential));
var endpoint = new Uri("https://atlas.microsoft.com");
var options = new MapsSearchClientOptions();
_clientDiagnostics = new ClientDiagnostics(options);
_pipeline = HttpPipelineBuilder.Build(options, new MapsSasCredentialPolicy(credential));
RestClient = new SearchRestClient(_clientDiagnostics, _pipeline, endpoint, null, options.Version);
}
/// <summary> Initializes a new instance of MapsSearchClient. </summary>
/// <param name="credential"> The Shared Access Signature credential used to connect to Azure. This signature
/// can be constructed using the <see cref="AzureSasCredential"/>.</param>
/// <param name="options"> The options for configuring the client. </param>
public MapsSearchClient(AzureSasCredential credential, MapsSearchClientOptions options)
{
Argument.AssertNotNull(credential, nameof(credential));
var endpoint = options.Endpoint;
options ??= new MapsSearchClientOptions();
_clientDiagnostics = new ClientDiagnostics(options);
_pipeline = HttpPipelineBuilder.Build(options, new MapsSasCredentialPolicy(credential));
RestClient = new SearchRestClient(_clientDiagnostics, _pipeline, endpoint, null, options.Version);
}
/// <summary>
/// The Get Polygon service allows you to request the geometry data such as a city or country outline for a set of entities, previously retrieved from an Online Search request in GeoJSON format. The geometry ID is returned in the sourceGeometry object under "geometry" and "id" in either a Search Address or Search Fuzzy call.
/// </summary>
/// <param name="geometryIds"> Comma separated list of geometry UUIDs, previously retrieved from an Online Search request. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<PolygonResult>> GetPolygonsAsync(IEnumerable<string> geometryIds, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetPolygons");
scope.Start();
try
{
return await RestClient.ListPolygonsAsync(JsonFormat.Json, geometryIds, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Get Polygon service allows you to request the geometry data such as a city or country outline for a set of entities, previously retrieved from an Online Search request in GeoJSON format. The geometry ID is returned in the sourceGeometry object under "geometry" and "id" in either a Search Address or Search Fuzzy call.
/// </summary>
/// <param name="geometryIds"> Comma separated list of geometry UUIDs, previously retrieved from an Online Search request. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<PolygonResult> GetPolygons(IEnumerable<string> geometryIds, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetPolygons");
scope.Start();
try
{
return RestClient.ListPolygons(JsonFormat.Json, geometryIds, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The basic default API is Free Form Search which handles the most fuzzy of inputs handling any combination of address or POI tokens. This search API is the canonical 'single line search'. The Free Form Search API is a seamless combination of POI search and geocoding. The API can also be weighted with a contextual position (lat./lon. pair), or fully constrained by a a pair of coordinates and radius, or it can be executed more generally without any geo biasing anchor point.<br><br>We strongly advise you to use the 'countrySet' parameter to specify only the countries for which your application needs coverage, as the default behavior will be to search the entire world, potentially returning unnecessary results.<br><br> E.g.: `countrySet`=US,FR <br><br>Please see <see href="https://docs.microsoft.com/azure/location-based-services/geocoding-coverage">Search Coverage</see> for a complete list of all the supported countries.<br><br>Most Search queries default to `maxFuzzyLevel`=2 to gain performance and also reduce unusual results. This new default can be overridden as needed per request by passing in the query param `maxFuzzyLevel`=3 or 4.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> FuzzySearchAsync(String query, FuzzySearchOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.FuzzySearch");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.FuzzySearchAsync(ResponseFormat.Json, query, options?.IsTypeAhead, options?.Top, options?.Skip, options?.CategoryFilter, options?.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, options?.BoundingBox != null ? options.BoundingBox.North + "," + options.BoundingBox.West : null, options?.BoundingBox != null ? options.BoundingBox.South + "," + options.BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.MinFuzzyLevel, options?.MaxFuzzyLevel, options?.IndexFilter, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, options?.EntityType, localizedMapView, options?.OperatingHours, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The basic default API is Free Form Search which handles the most fuzzy of inputs handling any combination of address or POI tokens. This search API is the canonical 'single line search'. The Free Form Search API is a seamless combination of POI search and geocoding. The API can also be weighted with a contextual position (lat./lon. pair), or fully constrained by a a pair of coordinates and radius, or it can be executed more generally without any geo biasing anchor point.<br><br>We strongly advise you to use the 'countrySet' parameter to specify only the countries for which your application needs coverage, as the default behavior will be to search the entire world, potentially returning unnecessary results.<br><br> E.g.: `countrySet`=US,FR <br><br>Please see <see href="https://docs.microsoft.com/azure/location-based-services/geocoding-coverage">Search Coverage</see> for a complete list of all the supported countries.<br><br>Most Search queries default to `maxFuzzyLevel`=2 to gain performance and also reduce unusual results. This new default can be overridden as needed per request by passing in the query param `maxFuzzyLevel`=3 or 4.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> FuzzySearch(String query, FuzzySearchOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.FuzzySearch");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.FuzzySearch(ResponseFormat.Json, query, options?.IsTypeAhead, options?.Top, options?.Skip, options?.CategoryFilter, options?.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, options?.BoundingBox != null ? options.BoundingBox.North + "," + options.BoundingBox.West : null, options?.BoundingBox != null ? options.BoundingBox.South + "," + options.BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.MinFuzzyLevel, options?.MaxFuzzyLevel, options?.IndexFilter, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, options?.EntityType, localizedMapView, options?.OperatingHours, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Points of Interest (POI) Search allows you to request POI results by name. Search supports additional query parameters such as language and filtering results by area of interest driven by country or bounding box. Endpoint will return only POI results matching the query string. Response includes POI details such as address, a pair of coordinates location and category.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="IsTypeAhead"> Boolean. If the typeahead flag is set, the query will be interpreted as a partial input and the search will enter predictive mode. </param>
/// <param name="OperatingHours"> Hours of operation for a POI (Points of Interest). The availability of hours of operation will vary based on the data available. If not passed, then no opening hours information will be returned. </param>
/// <param name="BoundingBox"> Bounding Box </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchPointOfInterestAsync(string query, bool? IsTypeAhead = null, OperatingHoursRange? OperatingHours = null, GeoBoundingBox BoundingBox = null, SearchPointOfInterestOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchPointOfInterest");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchPointOfInterestAsync(ResponseFormat.Json, query, IsTypeAhead, options?.Top, options?.Skip, options?.CategoryFilter, options?.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, BoundingBox != null ? BoundingBox.North + "," + BoundingBox.West : null, BoundingBox != null ? BoundingBox.South + "," + BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, OperatingHours, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Points of Interest (POI) Search allows you to request POI results by name. Search supports additional query parameters such as language and filtering results by area of interest driven by country or bounding box. Endpoint will return only POI results matching the query string. Response includes POI details such as address, a pair of coordinates location and category.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="IsTypeAhead"> Boolean. If the typeahead flag is set, the query will be interpreted as a partial input and the search will enter predictive mode. </param>
/// <param name="OperatingHours"> Hours of operation for a POI (Points of Interest). The availability of hours of operation will vary based on the data available. If not passed, then no opening hours information will be returned. </param>
/// <param name="BoundingBox"> Bounding Box </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchPointOfInterest(string query, bool? IsTypeAhead = null, OperatingHoursRange? OperatingHours = null, GeoBoundingBox BoundingBox = null, SearchPointOfInterestOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchPointOfInterest");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchPointOfInterest(ResponseFormat.Json, query, IsTypeAhead, options?.Top, options?.Skip, options?.CategoryFilter, options?.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, BoundingBox != null ? BoundingBox.North + "," + BoundingBox.West : null, BoundingBox != null ? BoundingBox.South + "," + BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, OperatingHours, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Nearby search API. If you have a use case for only retrieving POI results around a specific location, the nearby search method may be the right choice. This endpoint will only return POI results, and does not take in a search query parameter.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchNearbyPointOfInterestAsync(SearchNearbyPointOfInterestOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchNearbyPointOfInterest");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchNearbyPointOfInterestAsync(
ResponseFormat.Json,
Convert.ToDouble(options?.Coordinates?.Latitude, CultureInfo.InvariantCulture.NumberFormat),
Convert.ToDouble(options?.Coordinates?.Longitude, CultureInfo.InvariantCulture.NumberFormat),
options?.Top, options?.Skip, options?.CategoryFilter, options?.CountryFilter, options?.RadiusInMeters, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, cancellationToken
).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Nearby search API. If you have a use case for only retrieving POI results around a specific location, the nearby search method may be the right choice. This endpoint will only return POI results, and does not take in a search query parameter.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchNearbyPointOfInterest(SearchNearbyPointOfInterestOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchNearbyPointOfInterest");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchNearbyPointOfInterest(
ResponseFormat.Json,
Convert.ToDouble(options?.Coordinates?.Latitude, CultureInfo.InvariantCulture.NumberFormat),
Convert.ToDouble(options?.Coordinates?.Longitude, CultureInfo.InvariantCulture.NumberFormat),
options?.Top, options?.Skip, options?.CategoryFilter, options?.CountryFilter, options?.RadiusInMeters, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, cancellationToken
);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Get POI by Category API. Points of Interest (POI) Category Search allows you to request POI results from given category. Search allows to query POIs from one category at a time. Endpoint will only return POI results which are categorized as specified. Response includes POI details such as address, a pair of coordinates location and classification.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchPointOfInterestCategoryAsync(SearchPointOfInterestCategoryOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchPointOfInterestCategory");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchPointOfInterestCategoryAsync(ResponseFormat.Json, options?.query, options?.IsTypeAhead, options?.Top, options?.Skip, options?.CategoryFilter, options.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, options?.BoundingBox != null ? options.BoundingBox.North + "," + options.BoundingBox.West : null, options?.BoundingBox != null ? options.BoundingBox.South + "," + options.BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, options?.OperatingHours, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Get POI by Category API. Points of Interest (POI) Category Search allows you to request POI results from given category. Search allows to query POIs from one category at a time. Endpoint will only return POI results which are categorized as specified. Response includes POI details such as address, a pair of coordinates location and classification.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchPointOfInterestCategory(SearchPointOfInterestCategoryOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchPointOfInterestCategory");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchPointOfInterestCategory(ResponseFormat.Json, options?.query, options?.IsTypeAhead, options?.Top, options?.Skip, options?.CategoryFilter, options?.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, options?.BoundingBox != null ? options.BoundingBox.North + "," + options.BoundingBox.West : null, options?.BoundingBox != null ? options.BoundingBox.South + "," + options.BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.BrandFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, options?.OperatingHours, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Get POI Category Tree API. POI Category API provides a full list of supported Points of Interest (POI) categories and subcategories together with their translations and synonyms. The returned content can be used to provide more meaningful results through other Search Service APIs, like <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchpoi">Get Search POI</see>.
/// </summary>
/// <param name="language">
/// Language in which search results should be returned. Should be one of supported IETF language tags, except NGT and NGT-Latn. Language tag is case insensitive. When data in specified language is not available for a specific field, default language is used (English).
/// Please refer to <see href="https://docs.microsoft.com/azure/azure-maps/supported-languages">Supported Languages</see> for details.
/// </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<PointOfInterestCategoryTreeResult>> GetPointOfInterestCategoryTreeAsync(SearchLanguage? language = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetPointOfInterestCategoryTree");
scope.Start();
try
{
return await RestClient.GetPointOfInterestCategoryTreeAsync(JsonFormat.Json, language.ToString(), cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Get POI Category Tree API. POI Category API provides a full list of supported Points of Interest (POI) categories and subcategories together with their translations and synonyms. The returned content can be used to provide more meaningful results through other Search Service APIs, like <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchpoi">Get Search POI</see>.
/// </summary>
/// <param name="language">
/// Language in which search results should be returned. Should be one of supported IETF language tags, except NGT and NGT-Latn. Language tag is case insensitive. When data in specified language is not available for a specific field, default language is used (English).
/// Please refer to <see href="https://docs.microsoft.com/azure/azure-maps/supported-languages">Supported Languages</see> for details.
/// </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<PointOfInterestCategoryTreeResult> GetPointOfInterestCategoryTree(SearchLanguage? language = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetPointOfInterestCategoryTree");
scope.Start();
try
{
return RestClient.GetPointOfInterestCategoryTree(JsonFormat.Json, language.ToString(), cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Address geocoding. The geocoding is performed by hitting the geocode endpoint with just the address or partial address in question. The geocoding search index will be queried for everything above the street level data. No POIs will be returned. Note that the geocoder is very tolerant of typos and incomplete addresses. It will also handle everything from exact street addresses or street or intersections as well as higher level geographies such as city centers, counties, states etc.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks", "pizza"). Must be properly URL encoded. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchAddressAsync(string query, SearchAddressOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchAddressAsync(ResponseFormat.Json, query, options?.IsTypeAhead, options?.Top, options?.Skip, options?.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, options?.BoundingBox != null ? options.BoundingBox.North + "," + options.BoundingBox.West : null, options?.BoundingBox != null ? options.BoundingBox.South + "," + options.BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.EntityType, localizedMapView, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Address geocoding. The geocoding is performed by hitting the geocode endpoint with just the address or partial address in question. The geocoding search index will be queried for everything above the street level data. No POIs will be returned. Note that the geocoder is very tolerant of typos and incomplete addresses. It will also handle everything from exact street addresses or street or intersections as well as higher level geographies such as city centers, counties, states etc.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks", "pizza"). Must be properly URL encoded. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchAddress(string query, SearchAddressOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchAddress(ResponseFormat.Json, query, options?.IsTypeAhead, options?.Top, options?.Skip, options?.CountryFilter, options?.Coordinates?.Latitude, options?.Coordinates?.Longitude, options?.RadiusInMeters, options?.BoundingBox != null ? options.BoundingBox.North + "," + options.BoundingBox.West : null, options?.BoundingBox != null ? options.BoundingBox.South + "," + options.BoundingBox.East : null, options?.Language.ToString(), options?.ExtendedPostalCodesFor, options?.EntityType, localizedMapView, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Reverse geocode to an address. There may be times when you need to translate a pair of coordinates (example: 37.786505, -122.3862) into a human understandable street address. Most often this is needed in tracking applications where you receive a GPS feed from the device or asset and wish to know what address where the a pair of coordinates is located. This endpoint will return address information for a given coordinate.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<ReverseSearchAddressResult>> ReverseSearchAddressAsync(ReverseSearchOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.ReverseSearchAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.ReverseSearchAddressAsync(
ResponseFormat.Json,
new double[] {
Convert.ToDouble(options?.Coordinates?.Latitude, CultureInfo.InvariantCulture.NumberFormat),
Convert.ToDouble(options?.Coordinates?.Longitude, CultureInfo.InvariantCulture.NumberFormat)
},
options?.Language.ToString(), options?.IncludeSpeedLimit, options?.Heading, options?.RadiusInMeters, options?.StreetNumber?.ToString(CultureInfo.InvariantCulture), options?.IncludeRoadUse, options?.RoadUse, options?.AllowFreeformNewline, options?.IncludeMatchType, options?.EntityType, localizedMapView, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Reverse geocode to an address. There may be times when you need to translate a pair of coordinates (example: 37.786505, -122.3862) into a human understandable street address. Most often this is needed in tracking applications where you receive a GPS feed from the device or asset and wish to know what address where the a pair of coordinates is located. This endpoint will return address information for a given coordinate.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<ReverseSearchAddressResult> ReverseSearchAddress(ReverseSearchOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.ReverseSearchAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.ReverseSearchAddress(
ResponseFormat.Json,
new double[] {
Convert.ToDouble(options?.Coordinates?.Latitude, CultureInfo.InvariantCulture.NumberFormat),
Convert.ToDouble(options?.Coordinates?.Longitude, CultureInfo.InvariantCulture.NumberFormat)
},
options?.Language.ToString(), options?.IncludeSpeedLimit, options?.Heading, options?.RadiusInMeters, options?.StreetNumber?.ToString(CultureInfo.InvariantCulture), options?.IncludeRoadUse, options?.RoadUse, options?.AllowFreeformNewline, options?.IncludeMatchType, options?.EntityType, localizedMapView, cancellationToken
);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Reverse geocode to a cross street. There may be times when you need to translate a a pair of coordinates (example: 37.786505, -122.3862) into a human understandable cross street. Most often this is needed in tracking applications where you receive a GPS feed from the device or asset and wish to know what address where the a pair of coordinates is located.
/// This endpoint will return cross street information for a given coordinate.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<ReverseSearchCrossStreetAddressResult>> ReverseSearchCrossStreetAddressAsync(ReverseSearchCrossStreetOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.ReverseSearchCrossStreetAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.ReverseSearchCrossStreetAddressAsync(
ResponseFormat.Json,
new double[] {
Convert.ToDouble(options?.Coordinates?.Latitude, CultureInfo.InvariantCulture.NumberFormat),
Convert.ToDouble(options?.Coordinates?.Longitude, CultureInfo.InvariantCulture.NumberFormat)
},
options?.Top, options?.Heading, options?.RadiusInMeters, options?.Language.ToString(), localizedMapView, cancellationToken
).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Reverse geocode to a cross street. There may be times when you need to translate a a pair of coordinates (example: 37.786505, -122.3862) into a human understandable cross street. Most often this is needed in tracking applications where you receive a GPS feed from the device or asset and wish to know what address where the a pair of coordinates is located.
/// This endpoint will return cross street information for a given coordinate.
/// </summary>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<ReverseSearchCrossStreetAddressResult> ReverseSearchCrossStreetAddress(ReverseSearchCrossStreetOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.ReverseSearchCrossStreetAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.ReverseSearchCrossStreetAddress(
ResponseFormat.Json,
new double[] {
Convert.ToDouble(options?.Coordinates?.Latitude, CultureInfo.InvariantCulture.NumberFormat),
Convert.ToDouble(options?.Coordinates?.Longitude, CultureInfo.InvariantCulture.NumberFormat)
},
options?.Top, options?.Heading, options?.RadiusInMeters, options?.Language.ToString(), localizedMapView, cancellationToken
);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Structured address geocoding. The geocoding search index will be queried for everything above the street level data. No POIs will be returned. Note that the geocoder is very tolerant of typos and incomplete addresses. It will also handle everything from exact street addresses or street or intersections as well as higher level geographies such as city centers, counties, states etc.
/// </summary>
/// <param name="address"> structured address </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchStructuredAddressAsync(StructuredAddress address, SearchStructuredAddressOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchStructuredAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchStructuredAddressAsync(ResponseFormat.Json, address.CountryCode, options?.Language.ToString(), options?.Top, options?.Skip, address.StreetNumber, address.StreetName, address.CrossStreet, address.Municipality, address.MunicipalitySubdivision, address.CountryTertiarySubdivision, address.CountrySecondarySubdivision, address.CountrySubdivision, address.PostalCode, options?.ExtendedPostalCodesFor, options?.EntityType, localizedMapView, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Structured address geocoding. The geocoding search index will be queried for everything above the street level data. No POIs will be returned. Note that the geocoder is very tolerant of typos and incomplete addresses. It will also handle everything from exact street addresses or street or intersections as well as higher level geographies such as city centers, counties, states etc.
/// </summary>
/// <param name="address"> structured address </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchStructuredAddress(StructuredAddress address, SearchStructuredAddressOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchStructuredAddress");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchStructuredAddress(ResponseFormat.Json, address.CountryCode, options?.Language.ToString(), options?.Top, options?.Skip, address.StreetNumber, address.StreetName, address.CrossStreet, address.Municipality, address.MunicipalitySubdivision, address.CountryTertiarySubdivision, address.CountrySecondarySubdivision, address.CountrySubdivision, address.PostalCode, options?.ExtendedPostalCodesFor, options?.EntityType, localizedMapView, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Search inside geometry. The Search Geometry endpoint allows you to perform a free form search inside a single geometry or many of them. The search results that fall inside the geometry/geometries will be returned.<br><br>To send the geometry you will use a `POST` request where the request body will contain the `geometry` object represented as a `GeoJSON` type and the `Content-Type` header will be set to `application/json`. The geographical features to be searched can be modeled as Polygon and/or Circle geometries represented using any one of the following `GeoJSON` types:<ul><li>**GeoJSON FeatureCollection** <br>The `geometry` can be represented as a `GeoJSON FeatureCollection` object. This is the recommended option if the geometry contains both Polygons and Circles. The `FeatureCollection` can contain a max of 50 `GeoJSON Feature` objects. Each `Feature` object should represent either a Polygon or a Circle with the following conditions:<ul style="list-style-type:none"><li>A `Feature` object for the Polygon geometry can have a max of 50 coordinates and it's properties must be empty.</li><li>A `Feature` object for the Circle geometry is composed of a _center_ represented using a `GeoJSON Point` type and a _radius_ value (in meters) which must be specified in the object's properties along with the _subType_ property whose value should be 'Circle'.</li></ul><br> Please see the Examples section below for a sample `FeatureCollection` representation.<br><br></li><li>**GeoJSON GeometryCollection**<br>The `geometry` can be represented as a `GeoJSON GeometryCollection` object. This is the recommended option if the geometry contains a list of Polygons only. The `GeometryCollection` can contain a max of 50 `GeoJSON Polygon` objects. Each `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `GeometryCollection` representation.<br><br></li><li>**GeoJSON Polygon**<br>The `geometry` can be represented as a `GeoJSON Polygon` object. This is the recommended option if the geometry contains a single Polygon. The `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `Polygon` representation.<br><br></li></ul>.<br><br>
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="geometry"> This represents the geometry for one or more geographical features (parks, state boundary etc.) to search in and should be a GeoJSON compliant type. Please refer to <see href="https://tools.ietf.org/html/rfc7946">RFC 7946</see> for details. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchInsideGeometryAsync(String query, GeoObject geometry, SearchInsideGeometryOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchInsideGeometry");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchInsideGeometryAsync(ResponseFormat.Json, query, new SearchInsideGeometryRequest(geometry), options?.Top, options?.Language.ToString(), options?.CategoryFilter, options?.ExtendedPostalCodesFor, options?.IndexFilter, localizedMapView, options?.OperatingHours, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Search inside geometry. The Search Geometry endpoint allows you to perform a free form search inside a single geometry or many of them. The search results that fall inside the geometry/geometries will be returned.<br><br>To send the geometry you will use a `POST` request where the request body will contain the `geometry` object represented as a `GeoJSON` type and the `Content-Type` header will be set to `application/json`. The geographical features to be searched can be modeled as Polygon and/or Circle geometries represented using any one of the following `GeoJSON` types:<ul><li>**GeoJSON FeatureCollection** <br>The `geometry` can be represented as a `GeoJSON FeatureCollection` object. This is the recommended option if the geometry contains both Polygons and Circles. The `FeatureCollection` can contain a max of 50 `GeoJSON Feature` objects. Each `Feature` object should represent either a Polygon or a Circle with the following conditions:<ul style="list-style-type:none"><li>A `Feature` object for the Polygon geometry can have a max of 50 coordinates and it's properties must be empty.</li><li>A `Feature` object for the Circle geometry is composed of a _center_ represented using a `GeoJSON Point` type and a _radius_ value (in meters) which must be specified in the object's properties along with the _subType_ property whose value should be 'Circle'.</li></ul><br> Please see the Examples section below for a sample `FeatureCollection` representation.<br><br></li><li>**GeoJSON GeometryCollection**<br>The `geometry` can be represented as a `GeoJSON GeometryCollection` object. This is the recommended option if the geometry contains a list of Polygons only. The `GeometryCollection` can contain a max of 50 `GeoJSON Polygon` objects. Each `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `GeometryCollection` representation.<br><br></li><li>**GeoJSON Polygon**<br>The `geometry` can be represented as a `GeoJSON Polygon` object. This is the recommended option if the geometry contains a single Polygon. The `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `Polygon` representation.<br><br></li></ul>.<br><br>
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="geometryCollection"> This represents the geometry for one or more geographical features (parks, state boundary etc.) to search in and should be a GeoJSON compliant type. Please refer to <see href="https://tools.ietf.org/html/rfc7946">RFC 7946</see> for details. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchInsideGeometryAsync(String query, GeoCollection geometryCollection, SearchInsideGeometryOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchInsideGeometry");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchInsideGeometryAsync(ResponseFormat.Json, query, new SearchInsideGeometryRequest(geometryCollection), options?.Top, options?.Language.ToString(), options?.CategoryFilter, options?.ExtendedPostalCodesFor, options?.IndexFilter, localizedMapView, options?.OperatingHours, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Search inside geometry. The Search Geometry endpoint allows you to perform a free form search inside a single geometry or many of them. The search results that fall inside the geometry/geometries will be returned.<br><br>To send the geometry you will use a `POST` request where the request body will contain the `geometry` object represented as a `GeoJSON` type and the `Content-Type` header will be set to `application/json`. The geographical features to be searched can be modeled as Polygon and/or Circle geometries represented using any one of the following `GeoJSON` types:<ul><li>**GeoJSON FeatureCollection** <br>The `geometry` can be represented as a `GeoJSON FeatureCollection` object. This is the recommended option if the geometry contains both Polygons and Circles. The `FeatureCollection` can contain a max of 50 `GeoJSON Feature` objects. Each `Feature` object should represent either a Polygon or a Circle with the following conditions:<ul style="list-style-type:none"><li>A `Feature` object for the Polygon geometry can have a max of 50 coordinates and it's properties must be empty.</li><li>A `Feature` object for the Circle geometry is composed of a _center_ represented using a `GeoJSON Point` type and a _radius_ value (in meters) which must be specified in the object's properties along with the _subType_ property whose value should be 'Circle'.</li></ul><br> Please see the Examples section below for a sample `FeatureCollection` representation.<br><br></li><li>**GeoJSON GeometryCollection**<br>The `geometry` can be represented as a `GeoJSON GeometryCollection` object. This is the recommended option if the geometry contains a list of Polygons only. The `GeometryCollection` can contain a max of 50 `GeoJSON Polygon` objects. Each `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `GeometryCollection` representation.<br><br></li><li>**GeoJSON Polygon**<br>The `geometry` can be represented as a `GeoJSON Polygon` object. This is the recommended option if the geometry contains a single Polygon. The `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `Polygon` representation.<br><br></li></ul>.<br><br>
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="geometry"> This represents the geometry for one or more geographical features (parks, state boundary etc.) to search in and should be a GeoJSON compliant type. Please refer to <see href="https://tools.ietf.org/html/rfc7946">RFC 7946</see> for details. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchInsideGeometry(String query, GeoObject geometry, SearchInsideGeometryOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchInsideGeometry");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchInsideGeometry(ResponseFormat.Json, query, new SearchInsideGeometryRequest(geometry), options?.Top, options?.Language.ToString(), options?.CategoryFilter, options?.ExtendedPostalCodesFor, options?.IndexFilter, localizedMapView, options?.OperatingHours, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// Search inside geometry. The Search Geometry endpoint allows you to perform a free form search inside a single geometry or many of them. The search results that fall inside the geometry/geometries will be returned.<br><br>To send the geometry you will use a `POST` request where the request body will contain the `geometry` object represented as a `GeoJSON` type and the `Content-Type` header will be set to `application/json`. The geographical features to be searched can be modeled as Polygon and/or Circle geometries represented using any one of the following `GeoJSON` types:<ul><li>**GeoJSON FeatureCollection** <br>The `geometry` can be represented as a `GeoJSON FeatureCollection` object. This is the recommended option if the geometry contains both Polygons and Circles. The `FeatureCollection` can contain a max of 50 `GeoJSON Feature` objects. Each `Feature` object should represent either a Polygon or a Circle with the following conditions:<ul style="list-style-type:none"><li>A `Feature` object for the Polygon geometry can have a max of 50 coordinates and it's properties must be empty.</li><li>A `Feature` object for the Circle geometry is composed of a _center_ represented using a `GeoJSON Point` type and a _radius_ value (in meters) which must be specified in the object's properties along with the _subType_ property whose value should be 'Circle'.</li></ul><br> Please see the Examples section below for a sample `FeatureCollection` representation.<br><br></li><li>**GeoJSON GeometryCollection**<br>The `geometry` can be represented as a `GeoJSON GeometryCollection` object. This is the recommended option if the geometry contains a list of Polygons only. The `GeometryCollection` can contain a max of 50 `GeoJSON Polygon` objects. Each `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `GeometryCollection` representation.<br><br></li><li>**GeoJSON Polygon**<br>The `geometry` can be represented as a `GeoJSON Polygon` object. This is the recommended option if the geometry contains a single Polygon. The `Polygon` object can have a max of 50 coordinates. Please see the Examples section below for a sample `Polygon` representation.<br><br></li></ul>.<br><br>
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="geometryCollection"> This represents the geometry for one or more geographical features (parks, state boundary etc.) to search in and should be a GeoJSON compliant type. Please refer to <see href="https://tools.ietf.org/html/rfc7946">RFC 7946</see> for details. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchInsideGeometry(String query, GeoCollection geometryCollection, SearchInsideGeometryOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchInsideGeometry");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchInsideGeometry(ResponseFormat.Json, query, new SearchInsideGeometryRequest(geometryCollection), options?.Top, options?.Language.ToString(), options?.CategoryFilter, options?.ExtendedPostalCodesFor, options?.IndexFilter, localizedMapView, options?.OperatingHours, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Along Route endpoint allows you to perform a fuzzy search for POIs along a specified route. This search is constrained by specifying the `maxDetourTime` limiting measure.<br><br>To send the route-points you will use a `POST` request where the request body will contain the `route` object represented as a `GeoJSON LineString` type and the `Content-Type` header will be set to `application/json`. Each route-point in `route` is represented as a `GeoJSON Position` type i.e. an array where the _longitude_ value is followed by the _latitude_ value and the _altitude_ value is ignored. The `route` should contain at least 2 route-points.<br><br>It is possible that original route will be altered, some of it's points may be skipped. If the route that passes through the found point is faster than the original one, the `detourTime` value in the response is negative.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="maxDetourTime"> Maximum detour time of the point of interest in seconds. Max value is 3600 seconds. </param>
/// <param name="route"> This represents the route to search along and should be a valid `GeoJSON LineString` type. Please refer to <see href="https://tools.ietf.org/html/rfc7946#section-3.1.4">RFC 7946</see> for details. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressResult>> SearchPointOfInterestAlongRouteAsync(String query, int maxDetourTime, GeoLineString route, SearchAlongRouteOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchPointOfInterestAlongRoute");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return await RestClient.SearchAlongRouteAsync(ResponseFormat.Json, query, maxDetourTime, new SearchAlongRouteRequest(route), options?.Top, options?.BrandFilter, options?.CategoryFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, options?.OperatingHours, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Along Route endpoint allows you to perform a fuzzy search for POIs along a specified route. This search is constrained by specifying the `maxDetourTime` limiting measure.<br><br>To send the route-points you will use a `POST` request where the request body will contain the `route` object represented as a `GeoJSON LineString` type and the `Content-Type` header will be set to `application/json`. Each route-point in `route` is represented as a `GeoJSON Position` type i.e. an array where the _longitude_ value is followed by the _latitude_ value and the _altitude_ value is ignored. The `route` should contain at least 2 route-points.<br><br>It is possible that original route will be altered, some of it's points may be skipped. If the route that passes through the found point is faster than the original one, the `detourTime` value in the response is negative.
/// </summary>
/// <param name="query"> The POI name to search for (e.g., "statue of liberty", "starbucks"), must be properly URL encoded. </param>
/// <param name="maxDetourTime"> Maximum detour time of the point of interest in seconds. Max value is 3600 seconds. </param>
/// <param name="route"> This represents the route to search along and should be a valid `GeoJSON LineString` type. Please refer to <see href="https://tools.ietf.org/html/rfc7946#section-3.1.4">RFC 7946</see> for details. </param>
/// <param name="options"> additional options </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressResult> SearchPointOfInterestAlongRoute(string query, int maxDetourTime, GeoLineString route, SearchAlongRouteOptions options = null, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.SearchPointOfInterestAlongRoute");
scope.Start();
try
{
LocalizedMapView? localizedMapView = null;
if (options?.LocalizedMapView != null)
{
localizedMapView = new LocalizedMapView(options?.LocalizedMapView.ToString());
}
return RestClient.SearchAlongRoute(ResponseFormat.Json, query, maxDetourTime, new SearchAlongRouteRequest(route), options?.Top, options?.BrandFilter, options?.CategoryFilter, options?.ElectricVehicleConnectorFilter, localizedMapView, options?.OperatingHours, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchfuzzy">Search Fuzzy API</see> using just a single API call. You can call Search Address Fuzzy Batch API to run either asynchronously (async) or synchronously (sync). The async API allows caller to batch up to **10,000** queries and sync API up to **100** queries.
/// </summary>
/// <param name="queries"> The list of search fuzzy queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressBatchResult>> GetImmediateFuzzyBatchSearchAsync(IEnumerable<FuzzySearchQuery> queries, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetImmediateFuzzyBatchSearch");
scope.Start();
try
{
var batchRequests = MapsSearchClient.fuzzySearchQueriesToBatchRequestInternal(queries);
return await RestClient.FuzzySearchBatchSyncAsync(JsonFormat.Json, batchRequests, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchfuzzy">Search Fuzzy API</see> using just a single API call. You can call Search Address Fuzzy Batch API to run either asynchronously (async) or synchronously (sync). The async API allows caller to batch up to **10,000** queries and sync API up to **100** queries.
/// </summary>
/// <param name="queries"> The list of search fuzzy queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressBatchResult> GetImmediateFuzzyBatchSearch(IEnumerable<FuzzySearchQuery> queries, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetImmediateFuzzyBatchSearch");
scope.Start();
try
{
var batchRequests = MapsSearchClient.fuzzySearchQueriesToBatchRequestInternal(queries);
return RestClient.FuzzySearchBatchSync(JsonFormat.Json, batchRequests, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchaddress">Search Address API</see> using just a single API call. This Search Address Batch API can handle up to **100** queries.
/// To send more queries in a batch request, please refer to <see cref="MapsSearchClient.SearchAddressBatch(WaitUntil, IEnumerable<SearchAddressQuery>, CancellationToken)"/> long-running operation.
/// </summary>
/// <param name="queries"> The list of address geocoding queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<SearchAddressBatchResult>> GetImmediateSearchAddressBatchAsync(IEnumerable<SearchAddressQuery> queries, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetImmediateSearchAddressBatch");
scope.Start();
try
{
var batchRequests = MapsSearchClient.searchAddressQueriesToBatchRequestInternal(queries);
return await RestClient.SearchAddressBatchSyncAsync(JsonFormat.Json, batchRequests, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchaddress">Search Address API</see> using just a single API call. You can call Search Address Batch API to run either asynchronously (async) or synchronously (sync). The async API allows caller to batch up to **10,000** queries and sync API up to **100** queries.
/// To send more queries in a batch request, please refer to <see cref="MapsSearchClient.SearchAddressBatch(WaitUntil, IEnumerable<SearchAddressQuery>, CancellationToken)"/> long-running operation.
/// </summary>
/// <param name="queries"> The list of address geocoding queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<SearchAddressBatchResult> GetImmediateSearchAddressBatch(IEnumerable<SearchAddressQuery> queries, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetImmediateSearchAddressBatch");
scope.Start();
try
{
var batchRequests = MapsSearchClient.searchAddressQueriesToBatchRequestInternal(queries);
return RestClient.SearchAddressBatchSync(JsonFormat.Json, batchRequests, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchaddressreverse">Search Address Reverse API</see> using just a single API call. This Search Address Reverse Batch API can handle up to **100** queries.
/// To send more queries in a batch request, please refer to <see cref="MapsSearchClient.ReverseSearchAddressBatch(WaitUntil, IEnumerable<ReverseSearchAddressQuery>, CancellationToken)"/> long-running operation.
/// </summary>
/// <param name="queries"> The list of reverse geocoding queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<ReverseSearchAddressBatchResult>> GetImmediateReverseSearchAddressBatchAsync(IEnumerable<ReverseSearchAddressQuery> queries, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetImmediateReverseSearchAddressBatch");
scope.Start();
try
{
var batchRequests = MapsSearchClient.reverseSearchAddressQueriesToBatchRequestInternal(queries);
return await RestClient.ReverseSearchAddressBatchSyncAsync(JsonFormat.Json, batchRequests, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchaddressreverse">Search Address Reverse API</see> using just a single API call. This Search Address Reverse Batch API can handle up to **100** queries.
/// To send more queries in a batch request, please refer to <see cref="MapsSearchClient.ReverseSearchAddressBatch(WaitUntil, IEnumerable<ReverseSearchAddressQuery>, CancellationToken)"/> long-running operation.
/// </summary>
/// <param name="queries"> The list of reverse geocoding queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<ReverseSearchAddressBatchResult> GetImmediateReverseSearchAddressBatch(IEnumerable<ReverseSearchAddressQuery> queries, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.GetImmediateReverseSearchAddressBatch");
scope.Start();
try
{
var batchRequests = MapsSearchClient.reverseSearchAddressQueriesToBatchRequestInternal(queries);
return RestClient.ReverseSearchAddressBatchSync(JsonFormat.Json, batchRequests, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchfuzzy">Search Fuzzy API</see> using just a single API call. You can call Search Address Fuzzy Batch API to run either asynchronously (async) or synchronously (sync). The async API allows caller to batch up to **10,000** queries and sync API up to **100** queries.
/// </summary>
/// <param name="waitUntil"> <see cref="WaitUntil.Completed"/> if the method should wait to return until the long-running operation has completed on the service; <see cref="WaitUntil.Started"/> if it should return immediately after starting the operation. </param>
/// <param name="queries"> The list of search fuzzy queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentNullException"> <paramref name="queries"/> is null. </exception>
public virtual async Task<FuzzySearchBatchOperation> FuzzyBatchSearchAsync(WaitUntil waitUntil, IEnumerable<FuzzySearchQuery> queries, CancellationToken cancellationToken = default)
{
if (queries == null)
{
throw new ArgumentNullException(nameof(queries));
}
using var scope = _clientDiagnostics.CreateScope("MapsSearchClient.FuzzyBatchSearch");
scope.Start();
try
{
var batchRequests = MapsSearchClient.fuzzySearchQueriesToBatchRequestInternal(queries);
var originalResponse = await RestClient.FuzzySearchBatchAsync(JsonFormat.Json, batchRequests, cancellationToken).ConfigureAwait(false);
var operation = new FuzzySearchBatchOperation(this, new Uri(originalResponse.Headers.Location));
if (waitUntil == WaitUntil.Completed)
{
// TODO: Remove Thread.Sleep after adding RetryAfterInSeconds parameter
Thread.Sleep(400);
await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
}
return operation;
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary>
/// The Search Address Batch API sends batches of queries to <see href="https://docs.microsoft.com/rest/api/maps/search/getsearchfuzzy">Search Fuzzy API</see> using just a single API call. You can call Search Address Fuzzy Batch API to run either asynchronously (async) or synchronously (sync). The async API allows caller to batch up to **10,000** queries and sync API up to **100** queries.
/// </summary>
/// <param name="waitUntil"> <see cref="WaitUntil.Completed"/> if the method should wait to return until the long-running operation has completed on the service; <see cref="WaitUntil.Started"/> if it should return immediately after starting the operation. </param>
/// <param name="queries"> The list of search fuzzy queries/requests to process. The list can contain a max of 10,000 queries and must contain at least 1 query. </param>