2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
23 /// Reverse geocode request for map service.
25 /// <since_tizen>3</since_tizen>
26 public class ReverseGeocodeRequest : MapServiceRequest<PlaceAddress>
28 private Interop.ReverseGeocodeCallback _geocodeCallback;
29 private List<PlaceAddress> _addressList = new List<PlaceAddress>();
31 internal ReverseGeocodeRequest(MapService service, double latitude, double longitute) : base(service, ServiceRequestType.ReverseGeocode)
33 // The Maps Service invokes this callback when the address is obtained from the specified coordinates.
34 _geocodeCallback = (result, id, index, total, address, userData) =>
37 if (result.IsSuccess())
39 // The parameter address must be released using maps_address_destroy().
40 var addressHandle = new Interop.AddressHandle(address, needToRelease: true);
41 _addressList.Add(new PlaceAddress(addressHandle));
42 if (_addressList.Count == total)
44 _requestTask?.TrySetResult(_addressList);
49 // If search is failed, the value of total is 0 and address is NULL
50 _requestTask?.TrySetException(errorCode.GetException(errMessage));
54 startExecutionAction = new Action(() =>
57 errMessage = $"Failed to get coordinates for given coordinates: {latitude}:{longitute}";
58 errorCode = _service.handle.ReverseGeocode(latitude, longitute, _service.Preferences.handle, _geocodeCallback, IntPtr.Zero, out requestID);
59 if (errorCode.IsFailed() && errorCode != Interop.ErrorCode.Canceled)
61 _requestTask?.TrySetException(errorCode.GetException(errMessage));
63 _requestID = requestID;