d87117a6abf129fab71817eda170e7fe47253294
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / MultiReverseGeocodeRequest.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     /// Multiple reverse geocode request for Tizen map service.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     [Obsolete("Deprecated since API11. Might be removed in API13.")]
27     public class MultiReverseGeocodeRequest : MapServiceRequest<PlaceAddress>
28     {
29         private Interop.MultiReverseGeocodeCallback _geocodeCallback;
30         private List<PlaceAddress> _addressesList = new List<PlaceAddress>();
31
32         internal MultiReverseGeocodeRequest(MapService service, IEnumerable<Geocoordinates> coordinates) : base(service, ServiceRequestType.ReverseGeocode)
33         {
34             // The Maps Service invokes this callback once when gets the response from map service provider
35             // The value of total is same with requested coordinates list size. Even though one of address is not provided valid address handle is retrieved.
36             _geocodeCallback = (result, id, total, handle, userData) =>
37             {
38                 errorCode = result;
39                 if (result.IsSuccess())
40                 {
41                     var addressListHandle = new Interop.AddressListHandle(handle, needToRelease: true);
42                     var addressList = new PlaceAddressList(addressListHandle);
43                     _addressesList = addressList.Addresses as List<PlaceAddress>;
44                     _requestTask?.TrySetResult(_addressesList);
45                     return true;
46                 }
47                 else
48                 {
49                     _requestTask?.TrySetException(errorCode.GetException(errMessage));
50                     return false;
51                 }
52             };
53
54             var coordinateList = new GeocoordinatesList(coordinates);
55             startExecutionAction = new Action(() =>
56             {
57                 int requestID;
58                 errMessage = "Failed to get address list for given co-ordinate list";
59                 errorCode = _service.handle.MultiReverseGeocode(coordinateList.handle, _service.Preferences.handle, _geocodeCallback, IntPtr.Zero, out requestID);
60                 if (errorCode.IsFailed() && errorCode != Interop.ErrorCode.Canceled)
61                 {
62                     _requestTask?.TrySetException(errorCode.GetException(errMessage));
63                 }
64                 _requestID = requestID;
65             });
66         }
67     }
68 }