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 /// Place search request for Tizen map service
25 public class PlaceSearchRequest : MapServiceRequest<Place>
27 private Interop.Service.SearchPlaceCallback _responseCallback;
28 private List<Place> _placeList = new List<Place>();
29 private PlaceFilter _filter;
30 private PlaceSearchPreference _preferences;
32 internal PlaceSearchRequest(MapService service, Geocoordinates position, int distance) : this(service, ServiceRequestType.SearchPlace)
34 startExecutionAction = new Action(() =>
37 errMessage = string.Format("Failed to get place list for given co-ordinate {0} and distance {1}", position, distance);
38 errorCode = Interop.Service.SearchPlace(_service, position.handle, distance, _filter.handle, _preferences.handle, _responseCallback, IntPtr.Zero, out requestID);
39 if (errorCode.IsFailed() && errorCode != Interop.ErrorCode.Canceled)
41 _requestTask?.TrySetException(errorCode.GetException(errMessage));
43 _requestID = requestID;
47 internal PlaceSearchRequest(MapService service, Area boundary) : this(service, ServiceRequestType.SearchPlaceByArea)
49 startExecutionAction = new Action(() =>
52 errMessage = string.Format("Failed to get place list for given boundary {0}", boundary);
53 errorCode = Interop.Service.SearchPlaceByArea(_service, boundary.handle, _filter.handle, _preferences.handle, _responseCallback, IntPtr.Zero, out requestID);
54 if (errorCode.IsFailed() && errorCode != Interop.ErrorCode.Canceled)
56 _requestTask?.TrySetException(errorCode.GetException(errMessage));
58 _requestID = requestID;
62 internal PlaceSearchRequest(MapService service, string address, Area boundary) : this(service, ServiceRequestType.SearchPlaceByAddress)
64 startExecutionAction = new Action(() =>
67 errMessage = string.Format("Failed to get co-ordinates for given address {0} and boundary {1}", address, boundary);
68 errorCode = Interop.Service.SearchPlaceByAddress(_service, address, boundary.handle, _filter.handle, _preferences.handle, _responseCallback, IntPtr.Zero, out requestID);
69 if (errorCode.IsFailed() && errorCode != Interop.ErrorCode.Canceled)
71 _requestTask?.TrySetException(errorCode.GetException(errMessage));
73 _requestID = requestID;
77 private PlaceSearchRequest(MapService service, ServiceRequestType type) : base(service, type)
79 _filter = service._filter;
80 _preferences = service.PlaceSearchPreferences;
81 _responseCallback = (result, id, index, total, placeHandle, userData) =>
84 if (result.IsSuccess())
86 _placeList.Add(new Place(placeHandle));
87 if (_placeList.Count == total)
89 _requestTask?.TrySetResult(_placeList);
95 _requestTask?.TrySetException(errorCode.GetException(errMessage));