/
MapService.cs
executable file
·424 lines (391 loc) · 18.1 KB
/
MapService.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
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Tizen.Maps
{
/// <summary>
/// Map service class for service request.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public partial class MapService : IDisposable
{
internal Interop.ServiceHandle handle;
private PlaceFilter _filter;
private SearchPreference _searchPreference;
private static List<string> s_providers;
private string _serviceProvider;
/// <summary>
/// Creates a new maps service object for given service provider.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="serviceProvider">A string representing the name of the map service provider.</param>
/// <param name="serviceProviderKey">A string representing a certificate key to use the map service provider.</param>
/// <privilege>http://tizen.org/privilege/mapservice</privilege>
/// <privilege>http://tizen.org/privilege/network.get</privilege>
/// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
/// <exception cref="System.ArgumentException">Thrown when parameters are invalid.</exception>
/// <exception cref="System.InvalidOperationException">Thrown when a native operation failed to allocate memory and connect to the service.</exception>
/// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public MapService(string serviceProvider, string serviceProviderKey)
{
_serviceProvider = serviceProvider;
handle = new Interop.ServiceHandle(serviceProvider);
ProviderKey = serviceProviderKey;
PlaceSearchFilter = new PlaceFilter();
Preferences = new SearchPreference();
}
/// <summary>
/// Destroy the MapService object.
/// </summary>
~MapService()
{
Dispose(false);
}
/// <summary>
/// Gets the list of available map service providers.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <value>The list of map service providers.</value>
/// <privilege>http://tizen.org/privilege/mapservice</privilege>
/// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
/// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have privilege to access this property.</exception>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public static IEnumerable<string> Providers
{
get
{
if (s_providers != null) return s_providers;
s_providers = new List<string>();
Interop.ServiceHandle.ForeachProvider(provider => s_providers.Add(provider));
return s_providers;
}
}
/// <summary>
/// Gets the name of the map service provider.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public string Provider { get { return _serviceProvider; } }
/// <summary>
/// Gets a user consent for the map service provider
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <privilege>http://tizen.org/privilege/mapservice</privilege>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public bool UserConsented
{
get
{
return handle.UserConsented;
}
}
/// <summary>
/// Gets and sets a string representing keys for the map service provider.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <remarks>Typically, the provider key is issued by each maps provider after signing up for a plan in the website.
/// Depending on the plan and its provider which you have signed, you might have to pay for the network traffic.</remarks>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public string ProviderKey
{
get
{
return handle.ProviderKey;
}
set
{
handle.ProviderKey = value;
}
}
/// <summary>
/// Gets and sets a filter used for the place search result.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public PlaceFilter PlaceSearchFilter
{
get
{
return _filter;
}
set
{
if (value != null)
{
_filter = value;
}
}
}
/// <summary>
/// Gets the search preferences used for <see cref="GeocodeRequest"/> or <see cref="ReverseGeocodeRequest"/>.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public IGeocodePreference GeocodePreferences
{
get
{
return Preferences as IGeocodePreference;
}
}
/// <summary>
/// Gets the search preferences used for <see cref="PlaceSearchRequest"/>.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public IPlaceSearchPreference PlaceSearchPreferences
{
get
{
return Preferences as IPlaceSearchPreference;
}
}
/// <summary>
/// Gets the search preferences used for <see cref="RouteSearchRequest"/>.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public IRouteSearchPreference RouteSearchPreferences
{
get
{
return Preferences as IRouteSearchPreference;
}
}
/// <summary>
/// Gets and sets the search preferences.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public SearchPreference Preferences
{
get
{
if (_searchPreference == null)
{
_searchPreference = new SearchPreference(handle.Preferences);
}
return _searchPreference;
}
set
{
if (value != null)
{
handle.Preferences = value.handle;
_searchPreference = value;
}
}
}
/// <summary>
/// Gets the user's consent to use maps data.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <returns>Returns true if user agreed that the application can use maps data, otherwise false.</returns>
/// <privilege>http://tizen.org/privilege/mapservice</privilege>
/// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
/// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public async Task<bool> RequestUserConsent()
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Interop.RequestUserConsentwithHandleCallback cb = (consented, userData) =>
{
tcs.TrySetResult(consented);
};
var err = handle.RequestUserConsent(cb, IntPtr.Zero);
if (err.IsFailed())
{
tcs.TrySetException(err.GetException("Failed to get user consent"));
}
return await tcs.Task.ConfigureAwait(false);
}
/// <summary>
/// Checks if the maps service supports the given request.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="type">Request type to check</param>
/// <returns>Returns true if the maps service supports a request, otherwise false.</returns>
/// <privilege>http://tizen.org/privilege/mapservice</privilege>
/// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
/// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public bool IsSupported(ServiceRequestType type)
{
bool result = false;
var err = handle.IsServiceSupported((Interop.ServiceType)type, out result);
err.WarnIfFailed($"Failed to get if {type} is supported");
return (err.IsSuccess()) ? result : false;
}
/// <summary>
/// Checks if the maps service supports a given data feature.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="data">Data feature to check.</param>
/// <returns>Returns true if the maps service supports a data feature, otherwise false.</returns>
/// <privilege>http://tizen.org/privilege/mapservice</privilege>
/// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
/// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public bool IsSupported(ServiceData data)
{
bool result = false;
var err = handle.IsDataSupported((Interop.ServiceData)data, out result);
err.WarnIfFailed($"Failed to get if {data} data is supported");
return (err.IsSuccess()) ? result : false;
}
/// <summary>
/// Creates a geocode search request for the given free-formed address string.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="address">A string representing free-formed address.</param>
/// <returns>Returns a GeocodeRequest object created with an address string.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public GeocodeRequest CreateGeocodeRequest(string address)
{
return new GeocodeRequest(this, address);
}
/// <summary>
/// Creates a geocode search request for the given free-formed address string, within the specified boundary.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="address">A string representing the free-formed address.</param>
/// <param name="boundary">An instance of Area object representing the interested area.</param>
/// <seealso cref="Area"/>
/// <returns>Returns a GeocodeRequest object created with an address string and a specified boundary.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public GeocodeRequest CreateGeocodeRequest(string address, Area boundary)
{
return new GeocodeRequest(this, address, boundary);
}
/// <summary>
/// Creates a geocode search request for the given structured address.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="address">A string representing the address of interest.</param>
/// <returns>Returns a GeocodeRequest object created with a structured address.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public GeocodeRequest CreateGeocodeRequest(PlaceAddress address)
{
return new GeocodeRequest(this, address);
}
/// <summary>
/// Creates a reverse geocode search request for the given latitude and longitude.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="latitude">Latitude of the interested place.</param>
/// <param name="longitude">Longitude of the interested place.</param>
/// <returns>Returns a ReverseGeocodeRequest object created with the location coordinates.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public ReverseGeocodeRequest CreateReverseGeocodeRequest(double latitude, double longitude)
{
return new ReverseGeocodeRequest(this, latitude, longitude);
}
/// <summary>
/// Creates a reverse geocode search request for the given position coordinates list.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="coordinates">Coordinates list with [2 ~ 100] coordinates.</param>
/// <returns>Returns a MultiReverseGeocodeRequest object created with a list of location coordinates.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public MultiReverseGeocodeRequest CreateMultiReverseGeocodeRequest(IEnumerable<Geocoordinates> coordinates)
{
return new MultiReverseGeocodeRequest(this, coordinates);
}
/// <summary>
/// Creates a route search request for the origin and destination points.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="from">Starting point.</param>
/// <param name="to">Destination.</param>
/// <returns>Returns a RouteSearchRequest object created with the origin and destination coordinates.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public RouteSearchRequest CreateRouteSearchRequest(Geocoordinates from, Geocoordinates to)
{
return new RouteSearchRequest(this, from, to);
}
/// <summary>
/// Creates a place search request for a specified search radius around a given coordinates position.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="coordinates">Geographical coordinates of the center.</param>
/// <param name="distance">A double value representing the radius of an area to search places.</param>
/// <returns>Returns a PlaceSearchRequest object created with the location coordinates and search radius.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public PlaceSearchRequest CreatePlaceSearchRequest(Geocoordinates coordinates, int distance)
{
return new PlaceSearchRequest(this, coordinates, distance);
}
/// <summary>
/// Creates a place search request for places within a specified boundary.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="boundary">An instance of Area object representing and area to search interested places.</param>
/// <returns>Returns a PlaceSearchRequest object created with a specified boundary.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public PlaceSearchRequest CreatePlaceSearchRequest(Area boundary)
{
return new PlaceSearchRequest(this, boundary);
}
/// <summary>
/// Creates a place search request for a free-formed address within the boundary.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="address">A string which represents a free-formed address.</param>
/// <param name="boundary">An instance of area object representing an area to search interested places.</param>
/// <returns>Returns a PlaceSearchRequest object created with an address string and a specified boundary.</returns>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public PlaceSearchRequest CreatePlaceSearchRequest(string address, Area boundary)
{
return new PlaceSearchRequest(this, address, boundary);
}
#region IDisposable Support
private bool _disposedValue = false;
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
_filter?.Dispose();
_searchPreference?.Dispose();
}
handle?.Dispose();
_disposedValue = true;
}
}
/// <summary>
/// Releases all the resources used by this object.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated since API11. Might be removed in API13.")]
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}