Modify documentation of APIs
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / ReverseGeocodeRequest.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19
20 namespace Tizen.Maps
21 {
22     /// <summary>
23     /// Reverse geocode request for map service.
24     /// </summary>
25     public class ReverseGeocodeRequest : MapServiceRequest<PlaceAddress>
26     {
27         private Interop.ReverseGeocodeCallback _geocodeCallback;
28         private List<PlaceAddress> _addressList = new List<PlaceAddress>();
29
30         internal ReverseGeocodeRequest(MapService service, double latitude, double longitute) : base(service, ServiceRequestType.ReverseGeocode)
31         {
32             // The Maps Service invokes this callback when the address is obtained from the specified coordinates.
33             _geocodeCallback = (result, id, index, total, address, userData) =>
34             {
35                 errorCode = result;
36                 if (result.IsSuccess())
37                 {
38                     // The parameter address must be released using maps_address_destroy().
39                     var addressHandle = new Interop.AddressHandle(address, needToRelease: true);
40                     _addressList.Add(new PlaceAddress(addressHandle));
41                     if (_addressList.Count == total)
42                     {
43                         _requestTask?.TrySetResult(_addressList);
44                     }
45                 }
46                 else
47                 {
48                     // If search is failed, the value of total is 0 and address is NULL
49                     _requestTask?.TrySetException(errorCode.GetException(errMessage));
50                 }
51             };
52
53             startExecutionAction = new Action(() =>
54             {
55                 int requestID;
56                 errMessage = $"Failed to get co-ordinates for given Coordinate: {latitude}:{longitute}";
57                 errorCode = _service.handle.ReverseGeocode(latitude, longitute, _service.Preferences.handle, _geocodeCallback, IntPtr.Zero, out requestID);
58                 if (errorCode.IsFailed() && errorCode != Interop.ErrorCode.Canceled)
59                 {
60                     _requestTask?.TrySetException(errorCode.GetException(errMessage));
61                 }
62                 _requestID = requestID;
63             });
64         }
65     }
66 }