using System; using System.Diagnostics; using System.Threading.Tasks; using Tizen.Maps; using Xamarin.Forms.Maps.Tizen; using Xamarin.Forms.Platform.Tizen; namespace Xamarin { public static class FormsMaps { static MapService _mapService = null; static string ProviderName { get; set; } static string AuthenticationToken { get; set; } internal static bool IsInitialized { get; private set; } internal static MapService MapService { get { Debug.Assert(_mapService != null, "FormsMaps is not initialized"); return _mapService; } } public static void Init(string provider, string authenticationToken) { ProviderName = provider; AuthenticationToken = authenticationToken; if (IsInitialized) return; FormsApplication.RequestingUserConsentFunc = new Func(() => { TaskCompletionSource userConsentWaiter = new TaskCompletionSource(); UserConsentAction(userConsentWaiter); return userConsentWaiter.Task; }); } static async void UserConsentAction(TaskCompletionSource tcs) { var result = await MapService.RequestUserConsent(ProviderName); { if (result) { _mapService = new MapService(ProviderName, AuthenticationToken); if (_mapService != null) { GeocoderBackend.Register(); IsInitialized = true; } } else { Debug.WriteLine("Failed to get user consent which is required to use map service"); } tcs.SetResult(result); } } } }